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

Emit type annotations as written when generating .d.ts files #984

Closed
ahejlsberg opened this issue Oct 28, 2014 · 4 comments · May be fixed by Woodpile37/TypeScript#10
Closed

Emit type annotations as written when generating .d.ts files #984

ahejlsberg opened this issue Oct 28, 2014 · 4 comments · May be fixed by Woodpile37/TypeScript#10
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@ahejlsberg
Copy link
Member

If a type annotation is present it should be emitted exactly as written when generating a .d.ts file. For example:

module M {
    export type Value = string | number | boolean;
    export var x: Value;
}

The .d.ts file for the above is currently emitted as:

module M {
    export type Value = string | number | boolean;
    export var x: string | number | boolean;
}

The type annotation on x should be preserved and emitted exactly as written. Specifically, the declaration file emitter should only emit from Type objects when dealing with inferred types.

The current scheme of always emitting from Type objects actually leads to errors.

module M {
    type W = Window | string;
    export module N {
        export class Window { }
        export var p: W;
    }
}

Here, an error occurs when the emitter tries to emit Window | string in place of the W type annotation.

@DickvdBrink
Copy link
Contributor

This is fixed in master right, at least according to my manual testing.
So I think this one can be closed?
edit not sure if there is a test though

@danquirk
Copy link
Member

It does look like we need some tests for this, I don't see any .d.ts related tests in #1033. Need to double check whether these rules are codified in the latest spec yet.

@sheetalkamat
Copy link
Member

@DickvdBrink @danquirk , this is not completely fixed. We want to change this to emit type annotation as user wrote and I am working on that. I have the change but I am still adding tests to cover different scenarios. This should be in by mid week.

@sheetalkamat
Copy link
Member

#1122 handles this

@sheetalkamat sheetalkamat added the Fixed A PR has been merged for this issue label Nov 21, 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

Successfully merging a pull request may close this issue.

4 participants