Skip to content

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

Description

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.

Activity

  1. DickvdBrink commented on Nov 8, 2014

    @DickvdBrink
    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

  2. danquirk commented on Nov 10, 2014

    @danquirk
    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.

  3. sheetalkamat commented on Nov 10, 2014

    @sheetalkamat
    Member

    Dick van den Brink (@DickvdBrink) Dan Quirk (@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.

  4. sheetalkamat commented on Nov 11, 2014

    @sheetalkamat
    Member

    #1122 handles this

  5. locked and limited conversation to collaborators on Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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