Skip to content

No excess properties error on function return type #37017

Closed

Description

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

Activity

  1. IllusionMH commented on Feb 25, 2020

    @IllusionMH
    Contributor

    Duplicate of #12632 which requires #241

    (Sorry if couple of comments were posted - GH had issues with API)

  2. added
    Duplicate
    on Feb 25, 2020
  3. typescript-bot commented on Feb 28, 2020

    @typescript-bot
    Contributor

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

  4. added
    Fix Available
    on Sep 2, 2020
  5. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateFix Available

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions