Skip to content

Invalid d.ts file generated from valid input #361

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

Closed
rogierschouten opened this issue Aug 5, 2014 · 8 comments
Closed

Invalid d.ts file generated from valid input #361

rogierschouten opened this issue Aug 5, 2014 · 8 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@rogierschouten
Copy link

tsc generates a .d.ts file that it subsequently cannot parse anymore.

Input file: myfile.ts

/// <reference path="./used.d.ts" />
import myUsedId = require("used");
export class foo extends myUsedId.SomeClass {
}

Input file: used.d.ts

declare module "used" {
        // note: the following does work: export import bar = require("some_used_module");  
    import bar = require("some_used_module");  
    export import SomeClass = bar.SomeClass;
}
declare module "some_used_module" {
    export class SomeClass {

   }
}

Typescript command, tsc version 1.0.3.0:

tsc -m commonjs -d -t es5 ./myfile.ts

Output file myfile.d.ts

/// <reference path="used.d.ts" />
import myUsedId = require("used");
export declare class foo extends "some_used_module".SomeClass {
}

This output file cannot be used, it generates a compile error: TS1008: Unexpected token; 'type name' expected. It does so on the quoted "some_used_module".SomeClass.

Expected output file myfile.d.ts:

/// <reference path="used.d.ts" />
import myUsedId = require("used");
export declare class foo extends myUsedId .SomeClass {
}

A workaround is exporting bar from used.d.ts. However this breaks encapsulation unnecessarily, as ALL of bar is now exposed.

@basarat
Copy link
Contributor

basarat commented Aug 5, 2014

.d.ts files aren't supported for external modules at the moment. Old codeplex issue was : https://typescript.codeplex.com/workitem/2080 AFAIK it hasn't been moved to github,

@basarat
Copy link
Contributor

basarat commented Aug 5, 2014

.d.ts files aren't supported for external modules at the moment.

It might make more sense when combined with --out : #17

@rogierschouten
Copy link
Author

However, currently an NPM package "dts-bundle" exists for converting the tsc-generated typings to external-module-applicable typings. And that works perfectly but for this issue. If this were solved, then the use case for external modules has a proper workaround. Sounds pretty cheap to me.

@Bartvds
Copy link

Bartvds commented Aug 5, 2014

dts-bundle is a huge hack that relies on crude text transforms of regular .d.ts files. This functionality should be a feature of the compiler. Having this properly solved and being able to bundle .d.ts files in npm packages would help TS adoption in node.js space a lot.

@rogierschouten
Copy link
Author

@Bartvds I totally agree with you. And for the time being it would already be nice if the workaround worked.

@RyanCavanaugh
Copy link
Member

Confirmed in new compiler

@sheetalkamat
Copy link
Member

Fixed with 875d0c0

@rogierschouten
Copy link
Author

Great, thank you! I'm looking forward to the next release.

@mhegazy mhegazy closed this as completed Aug 14, 2014
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

6 participants