#Why can't I get type hints/autocomplete for `K extends keyof T` in this simple example

11 messages · Page 1 of 1 (latest)

red wren
#
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'
})
sick ginkgoBOT
#
krimson#7581

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'
})```

red wren
#

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

topaz needle
#

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:

sick ginkgoBOT
#
mkantor#7432

Preview:```ts
...
declare const example: <
_K extends "potato" | "potahto"

() => void

example<"">()
...```

tacit warren
#

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 :/

topaz needle
#

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

red wren
#

Thanks for confirming it's a known issue

#

! Resolved

#

! resolved