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

Pick allows any computed properties of type number #13906

Closed
AlexGalays opened this issue Feb 6, 2017 · 3 comments
Closed

Pick allows any computed properties of type number #13906

AlexGalays opened this issue Feb 6, 2017 · 3 comments
Labels
Needs Investigation This issue needs a team member to investigate its status.

Comments

@AlexGalays
Copy link

TypeScript Version: 2.1.5 and 2.2.0-dev.20170206

If we take the code meant to solve React's setState typings from here #12793

Code

function setState<T, K extends keyof T>(obj: T, state: Pick<T, K>) {
    for (let k in state) {
        obj[k] = state[k]
    }
}

interface Foo {
  a: string
  b: number
}

let foo: Foo = { a: "hello", b: 42 }

const someIndex = 8000
setState(foo, { [someIndex]: 'whatever' })

Expected behavior:
This should not compile. 8000 is not part of the keys of Foo

@AlexGalays
Copy link
Author

Any chance this could make it for 2.3?

@RyanCavanaugh
Copy link
Member

@ahejlsberg bug or something else going on here?

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label May 24, 2017
@AlexGalays
Copy link
Author

Good news, this is now fixed in TS 2.6.1

image

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

No branches or pull requests

2 participants