Skip to content

Optional constructor arguments with accessors are being added to .d.ts as optional class members #8788

Closed
@dustinhorne

Description

@dustinhorne

TypeScript Version:
nightly (1.9.0-beta-20160521-3)

When creating a class, if a parameter is added to the constructor as optional and given an accessor (such as private), the compiler generates it as an optional class member in the .d.ts file which then throws a syntax error.

Expected Behavior
Either field would be added to the class and set with the optional parameter, meaning it could be null or undefined or a syntax error is displayed at compile time.

Actual behavior:
Parameter is added as an optional class field resulting in an error.

Example class declaration:

export class Foo {
    constructor(private someValue?: any) { }
}

What The Compiler Produces in the Resulting .d.ts:

class Foo {
    private someValue?;
}

and the following error:
Error TS1112 A class member cannot be declared optional.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions