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

[bug] Declaration files not generated for files with only interfaces/no javascript. #49

Closed
superamadeus opened this issue May 17, 2017 · 3 comments

Comments

@superamadeus
Copy link

Due to some long-standing issue with awesome-typescript-loader:

s-panferov/awesome-typescript-loader#411
s-panferov/awesome-typescript-loader#428
s-panferov/awesome-typescript-loader#432

Files with no javascript-producing code are omitted from the declaration file process. For example:

Case 1:

// src/color-interface.ts
export interface ColorInterface {
   r: number;
   g: number;
   b number;
}

// src/color.ts
import { ColorInterface } from './color-interface';

export class Color implements ColorInterface {
   r: number;
   g: number;
   b number;
}

Case 2:

// src/color-interface.ts
export interface ColorInterface {
   r: number;
   g: number;
   b number;
}

export var __WORKAROUND = 1;

// src/color.ts
import { ColorInterface } from './color-interface';

export class Color implements ColorInterface {
   r: number;
   g: number;
   b number;
}

In Case 1, types/color-interface.d.ts is not generated, but types/color.d.ts is generated. Furthermore, types/color.d.ts contains a non-resolvable reference to ./color-interface.

In Case 2, both types/color-interface.d.ts and types/color.d.ts are generated and everything works as expected.

This occurs silently-- webpack throws no errors when building the library, but errors appear when trying to use the library from a consuming project:

// main.ts
import { Color } from 'my-library';

let color = new Color();
ERROR in [at-loader*] ./node_modules/my-library/dist/types/color.d.ts:1:31
    TS2307: Cannot find module './color-interface'.

*note that the error above mentions at-loader, this is just because I happen to be using at-loader in my other project. The error is due to the fact that types/color-interface.d.ts does not exist.

Probable fix (not sure of other implications, haven't tested):

  • switch from awesome-typescript-loader to ts-loader
  • install babel-loader
  • add babel-loader to /\.ts$/ rule before ts-loader (like so)
    module: {
            rules: [
                {
                    test: /\.ts$/,
                    use: [
                        {
                            loader: 'babel-loader'
                        },
                        {
                            loader: 'ts-loader',
                        }
                    ]
                }
            ]
        },
  • change declarationDir in tsconfig.json to types (as tsloader appears to use the provided path relative to the webpack config's output.path)

Again, this needs testing. I'll do a pull request shortly.

@alexjoverm
Copy link
Owner

Forgot to close this issue...

Thanks @superamadeus! This is how it was at the beginning, switched to awesome-typescript-loader for same reasons (bugs) but seems now that ts-loader got better :)

@alexjoverm
Copy link
Owner

Somehow I got confused and thought this was fixed

@alexjoverm alexjoverm reopened this May 26, 2017
@alexjoverm
Copy link
Owner

Fixed by 75dd59b. Now there is no more loaders for TypeScript compiling :)

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

Successfully merging a pull request may close this issue.

2 participants