Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack does not recompile non-.d.ts type definitions #808

Closed
liangchunn opened this issue Jul 17, 2018 · 5 comments
Closed

Webpack does not recompile non-.d.ts type definitions #808

liangchunn opened this issue Jul 17, 2018 · 5 comments

Comments

@liangchunn
Copy link

Webpack does not detect changes made to a pure types file in --watch mode on incremental builds.
I have been struggling with this issue; it's somehow related to #697, but with non-.d.ts files.

// types.ts
export interface AmbientType {
    a: number,
    b: string
}
// index.ts
import { AmbientType } from './types'

const test: AmbientType = {
    a: 2,
    b: ''
}

// tslint:disable-next-line
console.log(test)

After starting webpack in watch mode, removing b: string from types.ts and saving, no errors are emitted.

Expected Behaviour

Webpack recompiles non- .d.ts type definitions

Actual Behaviour

Webpack does not detect changes in types.ts on incremental builds, but fails on a cold build.

Steps to Reproduce the Problem

  1. git clone https://github.com/liangchunn/not-recompiling-ts.git
  2. cd not-recompiling-ts
  3. yarn install
  4. yarn start
  5. Remove b: string in src/types.ts and save
  6. No type errors are reported

Location of a Minimal Repository that Demonstrates the Issue.

https://github.com/liangchunn/not-recompiling-ts

Dependency versions

  • webpack@4.12.0
  • ts-loader@4.4.1
  • typescript@2.9.2

webpack.config.json

https://github.com/liangchunn/typescript-node-scripts/blob/master/lib/webpack.config.dev.js

@liangchunn liangchunn changed the title Webpack does not recompile non-d.ts type definitions Webpack does not recompile non-.d.ts type definitions Jul 17, 2018
@liangchunn
Copy link
Author

I've found a workaround to this issue by using transpileOnly: true for ts-loader and leveraging fork-ts-checker-webpack-plugin to do the type checking.

Ambient type definitions are still not reloading on save ( issue being tracked here TypeStrong/fork-ts-checker-webpack-plugin#36 ), but it does not 'persist' across incremental builds anymore.

@janwirth
Copy link

@liangchunn we have the same issue but pure type definition files are not recompiling - The issue you referenced is exactly about this. Do you have a fix? Would you mind sharing your setup?

@liangchunn
Copy link
Author

@FranzSkuffka

AFAIK pure .d.ts files will not recompile automatically; you would need to manually trigger an incremental build by saving a non-.d.ts file.

Here's my configuration for reference: https://github.com/liangchunn/typescript-node-scripts/blob/master/lib/webpack.config.dev.js
(added in this commit liangchunn/typescript-node-scripts@2efac52#diff-937ab2cb5e706721058c9c4712c8208a)

Viel Glück!

@ZSkycat
Copy link

ZSkycat commented Oct 25, 2018

I have encountered the same problem. The reason for this problem is not just a pure types file, but a ts file that is not actually used. That is, only type or interface is imported.

This problem can be solved by import './type';

Don't worry. The webpack production mode can removes empty modules and tree shaking. This won't have extra code being packaged. 😄

my case

type.ts

export interface InterfaceA {
    a1: number;
    a2: string;
}

export function test() {
    console.log('test');
}

index.ts

import { InterfaceA } from './type';
// import './type';

export function app(value: InterfaceA) {
    console.log(value.a1.toFixed(0));
    console.log(value.a2.trim());
}

@jlost
Copy link

jlost commented Apr 6, 2020

Shouldn't there be a solution to this problem that isn't just a workaround? Is it even possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants