Skip to content

Intersection type from Function and object literal type doesn't work #22877

Closed
@cshaa

Description

@cshaa

TypeScript Version: 2.7.2

Search Terms: Function interface, object literal type, intersection, type alias

Code

type MyConstructorType = Function & {prototype: {foo: number}};
let bar = (function () { }) as MyConstructorType;
bar.prototype.foo();

or equivalent:

let bar = (function () { }) as Function & {prototype: {foo: number}};
bar.prototype.foo();

doesn't even depend on the order

let bar = (function () { }) as {prototype: {foo: number}} & Function;
bar.prototype.foo();

Expected behavior:
The function call bar.prototype.foo() should throw a compile time error, as foo is marked as a number.

Actual behavior:
The property bar.prototype is of type any, no matter the intersection type.

Playground Link: here

Related Issues: #17757

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions