#How can I assert the contents of a function in conjunction with `ReturnType<T>`?
12 messages · Page 1 of 1 (latest)
Preview:```ts
type F = {
k: <K>(arg: K) => K
}
type Test<O extends Record<any, any>> = {
[Key in keyof O]: O[Key] extends (
arg: number
) => number
? ReturnType<O[Key]>
: null
}
type Res = Test<F>```
The type of K isn't determined until you execute the function, so it can't really reason about the the types
One message removed from a suspended account.
u.mergeDocument(true)
If you specify the type on F then it can infer the types:
type F<K> = {
k: (arg: K) => K
}
type Test<O extends Record<any, any>> = {
[Key in keyof O]: O[Key] extends (arg: number) => number ? ReturnType<O[Key]> : null
}
type Res1 = Test<F<string>>
type Res2 = Test<F<number>>
One message removed from a suspended account.
Correct, because the type belongs to the function, so it means the type is only known when the function is called
One message removed from a suspended account.
const entitites = createServicesFramework({