Closed
Description
π Search Terms
cannot be used to index type
Generics
forwardRef
π Version & Regression Information
- This changed in commit
β― Playground Link
π» Code
declare const f: <T>(f: (x: T) => unknown) => (x: T) => unknown
// making this a real identity function eliminates the error:
// declare const f: <T>(x: T) => T
declare const g: <T extends unknown>(x: { foo: T }) => unknown
// removing the generic constraint eliminates the error:
// declare const g: <T>(x: { foo: T }) => unknown
const h = f(g)
// explicitly writing out the exact type shown in type info eliminates the error:
// declare const a: <T extends unknown>(x: { foo: T }) => unknown
type FirstParameter<T> = T extends (x: infer P) => unknown ? P : unknown
// having the else branch use `never` eliminates the error:
// type FirstParameter<T> = T extends (x: infer P) => unknown ? P : never
type X = FirstParameter<typeof h>['foo']
π Actual behavior
Starting after said commit, this errors with: Type '"foo"' cannot be used to index type 'FirstParameter<(<T extends unknown>(x: { foo: T; }) => unknown)>'.
π Expected behavior
No error, and types inferred as before
Additional information about the issue
This was initially detected with a more complex example, you can find it here on TS discord https://discord.com/channels/508357248330760243/1255537732730491012/1255537732730491012 but was narrowed down thanks to @mkantor.
I already pinged the initial author @Andarist and he started looking at it.