Skip to content

Type () => T accepts a function that returns an object with properties not inside T.Β #54661

Closed as not planned
@LuisFerLCC

Description

@LuisFerLCC

Bug Report

πŸ”Ž Search Terms

  • Function return
  • Object
  • Property
  • Properties

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about object properties.

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

interface Test {
    a?: string;
    b?: string;
    c?: string;
}

const func: () => Test = () => ({
    a: "",

    // This property should throw an error
    d: ""
});

πŸ™ Actual behavior

The compiler does not throw any errors, allowing the function to return an object with properties that are not present in interface Test.

πŸ™‚ Expected behavior

The compiler should throw an error since property d does not exist on interface Test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions