Skip to content

Declaration emit widens literal types in readonly properties #15881

Closed
@evmar

Description

@evmar

TypeScript Version: 2.3.1
Code

$ cat > foo.ts
export const FOO = 'FOO';
export class Bar { readonly type = FOO; }
$ tsc --declaration foo.ts
$ cat foo.d.ts
export declare const FOO = "FOO";
export declare class Bar {
    readonly type: string;
}

EDIT: added readonly to clarify bug report

Expected behavior:
Bar.type is of type "FOO"

Actual behavior:
The type falls back to string

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts files

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions