Skip to content
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

Return value of higher order functions looses excess property checks #39635

Closed
essenmitsosse opened this issue Jul 17, 2020 · 2 comments
Closed
Labels
Duplicate An existing issue was already created Fix Available A PR has been opened for this issue

Comments

@essenmitsosse
Copy link

TypeScript Version: 3.9.2 (doesn't work in any version I tested, including 4)

Search Terms:
higher order function return value object excess property check

Code

interface Foo {
	foo: {
		bar: number
	}
}

// Error for unknown property buz
const getFoo = (): Foo  => ({
	foo: {
		bar: 1,
		buz: 2,
	}
})

// Typeing should be the same. Autocomplete works, but no error is shown for the excessive property buz
const getFoo3 = (): () => Foo  => () => ({
	foo: {
		bar: 1,
		buz: 2
	}
})

// Same problem as above. The issue doesn't seem to be directly related to higher order functions
const getFoo2: () => Foo = ()  => ({
	foo: {
		bar: 1,
		buz: 2,
	}
})

Expected behavior:
Error should be thrown for the excess property in all cases.

Actual behavior:
Error for excess properties is only thrown, when the return value of the function is directly typed.

Playground Link

Related Issues: -

@RyanCavanaugh
Copy link
Member

Duplicate #241

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jul 17, 2020
@typescript-bot
Copy link
Collaborator

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

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 Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants