#Why can't I get type hints/autocomplete for `K extends keyof T` in this simple example
11 messages · Page 1 of 1 (latest)
Preview:```ts
type TPerson = {
readonly firstName: string
readonly lastName: string
}
const partialAttribute = <T, K extends keyof T>(
attrs: Pick<T, K>
) => {
return "s"
}
partialAttribute<TPerson, "">({
// ^ no type autocomplete type hint for 'keyof K'
})```
If you open it up and place your cursor there and trigger auto complete, you don't get any autocomplete. Why is this?
Why can't I get type hints/autocomplete for K extends keyof T in this simple example
i think that's just not a position where type-aware autocomplete suggestions are ever offered. at least i can't make them happen. see this much simpler example:
Preview:```ts
...
declare const example: <
_K extends "potato" | "potahto"
() => void
example<"">()
...```
Having auto-complete for "keyof T" inside the generic definition works for variable scoped. I'm actually using that right now. But I guess it does not work for function scoped generic :/
yeah, i guess it does work for generic type instantiations like this:
type Example<T extends 'potato' | 'potahto'> = unknown
declare const x: Example<''>
// ^
too bad it doesn't for generic function type parameters. looks like there is already an open issue about it: https://github.com/microsoft/TypeScript/issues/28662