Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ctr52 opened this issue Jun 24, 2018 · 3 comments
Closed

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

ctr52 opened this issue Jun 24, 2018 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@ctr52
Copy link

ctr52 commented Jun 24, 2018

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',
})
@OYangXiao
Copy link

OYangXiao commented Jun 25, 2018

I‘ve also encountered this problem, this is what my code looks like

interface ITest {
  [name: string]: () => { one1: 1 };
}

const TestImpl: ITest = {
  test: function() {
    return { one: 1, two: 2 };
  }
};

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jun 25, 2018
@RyanCavanaugh
Copy link
Member

Duplicate #12632

@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants