Skip to content

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

@ahejlsberg

Description

@ahejlsberg

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.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions