Skip to content

Inconsistent function return type vs return type #28634

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
BrendonSled opened this issue Nov 21, 2018 · 2 comments
Closed

Inconsistent function return type vs return type #28634

BrendonSled opened this issue Nov 21, 2018 · 2 comments
Assignees
Labels
Bug A bug in TypeScript Duplicate An existing issue was already created Fix Available A PR has been opened for this issue

Comments

@BrendonSled
Copy link

TypeScript Version: 3.3.0-dev.20181121

Search Terms: function types, return types, inconsistent

Code

const test = { 1: '', 2: '', 3: '' };

type keys = { [key in keyof typeof test]: string };
type StateFunction<TState> = () => TState;

const a: StateFunction<keys> = () => ({ ...test, 4: '' }); //Does not error

const b = (): keys => ({ ...test, 4: '' }); //Errors properly

Expected behavior:
const a: StateFunction<keys> = () => ({ ...test, 4: '' }); Should error

Actual behavior:
const a: StateFunction<keys> = () => ({ ...test, 4: '' }); Does not error

Playground Link: http://www.typescriptlang.org/play/#src=const%20test%20%3D%20%7B%201%3A%20''%2C%202%3A%20''%2C%203%3A%20''%20%7D%3B%0D%0A%0D%0Atype%20keys%20%3D%20%7B%20%5Bkey%20in%20keyof%20typeof%20test%5D%3A%20string%20%7D%3B%0D%0Atype%20StateFunction%3CTState%3E%20%3D%20()%20%3D%3E%20TState%3B%0D%0A%0D%0Aconst%20a%3A%20StateFunction%3Ckeys%3E%20%3D%20()%20%3D%3E%20(%7B%20...test%2C%204%3A%20''%20%7D)%3B%0D%0A%0D%0Aconst%20b%20%3D%20()%3A%20keys%20%3D%3E%20(%7B%20...test%2C%204%3A%20''%20%7D)%3B

@BrendonSled BrendonSled changed the title Inconsistent function type vs return type Inconsistent function return type vs return type Nov 21, 2018
@weswigham
Copy link
Member

#241 strikes again, I think.

@weswigham weswigham added Bug A bug in TypeScript Needs Investigation This issue needs a team member to investigate its status. labels Nov 26, 2018
@rbuckton rbuckton added this to the TypeScript 3.3 RC milestone Nov 26, 2018
@weswigham weswigham added the Duplicate An existing issue was already created label Jan 14, 2019
@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.

@RyanCavanaugh RyanCavanaugh removed the Needs Investigation This issue needs a team member to investigate its status. label Mar 7, 2019
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Sep 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript 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.

5 participants