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

Compiler Doesn't Enforce Generic Return Type on Callable Signature #33908

Closed
berwyn opened this issue Oct 9, 2019 · 2 comments
Closed

Compiler Doesn't Enforce Generic Return Type on Callable Signature #33908

berwyn opened this issue Oct 9, 2019 · 2 comments
Labels
Fix Available A PR has been opened for this issue

Comments

@berwyn
Copy link

berwyn commented Oct 9, 2019

TypeScript Version: 3.5.3 - 3.7.0-dev.20191009

Search Terms: return type enforcement generic callable signature

Code

interface Foo {
  value: number
}

type SomeCallType<T> = () => T;

const example: SomeCallType<Foo> = () => ({ value: 1, bar: 2 })

Expected behavior:
The above sample should not compile and instead emit ts(2322) because bar is not a valid property for Foo

Actual behavior:
The code will in fact compile and emit as if nothing were the matter.

Playground Link: here

Related Issues:
These may be related, given that they involve other cases where return types don't appear to be correctly enforced on callable signatures:

@jack-williams
Copy link
Collaborator

Duplicate of #12632, though the issue is tracked by #241.

@berwyn
Copy link
Author

berwyn commented Oct 9, 2019

Aha, my bad! I admit, I only dug through the first 3-4 pages of results for my query so I missed that one. Closing in favour of #241.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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