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

keyof behavior in 2.9 #24574

Closed
domoritz opened this issue Jun 1, 2018 · 1 comment
Closed

keyof behavior in 2.9 #24574

domoritz opened this issue Jun 1, 2018 · 1 comment

Comments

@domoritz
Copy link

domoritz commented Jun 1, 2018

TypeScript Version: 2.9

Code

export interface Dict<T> {
  [key: string]: T;
}

type a = Dict<boolean>;

type b = keyof a;

Expected behavior:

b should be string

Actual behavior:

b is string | number

Maybe there is a simple fix to this but I cannot find anything. My temporary fix is to use "keyofStringsOnly": true.

Playground Link:

http://www.typescriptlang.org/play/#src=export%20interface%20Dict%3CT%3E%20%7B%0D%0A%20%20%5Bkey%3A%20string%5D%3A%20T%3B%0D%0A%7D%0D%0A%0D%0Atype%20a%20%3D%20Dict%3Cboolean%3E%3B%0D%0A%0D%0Atype%20b%20%3D%20keyof%20a%3B

Related Issues:

#24560 may be the same but I cannot tell.

@domoritz
Copy link
Author

domoritz commented Jun 1, 2018

My use case works with Extract.

export const keys = Object.keys as <T>(o: T) => (Extract<keyof T, string>)[];

#12253

@domoritz domoritz closed this as completed Jun 1, 2018
@microsoft microsoft locked and limited conversation to collaborators Aug 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant