Skip to content

Object.keys should return keyof T #733

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
fregante opened this issue Jun 22, 2019 · 2 comments
Closed

Object.keys should return keyof T #733

fregante opened this issue Jun 22, 2019 · 2 comments

Comments

@fregante
Copy link

fregante commented Jun 22, 2019

Playground: https://www.typescriptlang.org/play/#src=const%20feature%20%3D%20%7B%0D%0A%09description%3A%20''%2C%0D%0A%09screenshot%3A%20''%2C%0D%0A%09disabled%3A%20''%0D%0A%7D%3B%0D%0A%0D%0Aconst%20keys%20%3D%20Object.keys(feature)%3B

const feature = {
	description: '',
	screenshot: '',
	disabled: ''
};

const list = Object.keys(feature);

Current

keys(o: {}): string[];
typeof list = string[]

Expected

keys<T extends object>(o: T): Array<keyof T>;
typeof list = Array<"description" | "screenshot" | "disabled">

Workaround

const feature = {
	description: '',
	screenshot: '',
	disabled: ''
};

const list = Object.keys(feature) as Array<keyof typeof feature>;
@saschanaz
Copy link
Contributor

Object.keys is not on TSJS-lib-generator. It should be directly fixed in TypeScript repo.

@fregante
Copy link
Author

Indeed, moved to microsoft/TypeScript#32321

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants