Skip to content

Typescript not reported about extra key in returned object in function #25178

Closed
@ctr52

Description

@ctr52

TypeScript Version: 2.9

Search Terms: excess key in returned object in function
Code

interface ITestFunctionReturns {
    key1: number,
    key2: string,
}
type ITestFunction = () => ITestFunctionReturns

const testFunction: ITestFunction = () => ({
    asd: true,
    key1: 123,
    key2: 'str',
})

Expected behavior: typescript will report about extra key in the object

Actual behavior: I must point the interface in yet another place, without this typescript does not report an error

interface ITestFunctionReturns {
    key1: number,
    key2: string,
}
type ITestFunction = () => ITestFunctionReturns

const testFunction: ITestFunction = (): ITestFunctionReturns => ({
    asd: true,
    key1: 123,
    key2: 'str',
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions