Skip to content

No excess properties error on function return type #37017

Closed
@mgiedrius

Description

@mgiedrius

TypeScript Version: Nightly, 3.7.5

Search Terms: excess property, computed property

Code

const a = <T>(shape: T | (() => T)): T => {
    return shape instanceof Function ? shape() : shape;
}
        
//Case 1
a<{ x: string }>(() => ({ x: '', o: '' })); // I expect this to fail

//Case 2
a<{ x: string }>({ x: '', o: '' }); // Fails as expected

Expected behavior:
I expect Case 1 to show error similar to Case 2 because returned object contains more properties than described in generic type.

Actual behavior:
Case 1 is a valid typescript

Playground Link: Playground Link

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already createdFix AvailableA PR has been opened for this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions