Typescript: Ambient class can merge with concrete function

Created on 14 Aug 2019  路  7Comments  路  Source: microsoft/TypeScript

declare class C {

}

function C() {

}
Working as Intended

All 7 comments

Intentional and tested.

(This is analogous to how a concrete class can merge with an interface that adds more behavior that isn't implemented)

Feel free to add to the release notes if you'd like~

Yes, this means you can actually declare callable constructors in proper _TS_ implementation code now.

export declare class Point2D {
    x: number;
    y: number;
    constructor(x: number, y: number);
}
export function Point2D(this: Point2D | undefined, x: number, y: number) {
    if (!(this instanceof Point2D)) {
        return new Point2D(x, y);
    }
    this.x = x;
    this.y = y;
}

That's why it closed out ole issue #183.

Seems reasonable.

This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Was this page helpful?
0 / 5 - 0 ratings