#Get exact field type from interface using `keyof`
3 messages · Page 1 of 1 (latest)
Preview:```ts
interface Foo {
a: string
b: number
}
type Opts<K extends keyof Foo = keyof Foo> = Record<
K,
Foo[K]
const opts: Opts = {
a: 5, // should force to string
b: "t", // should force to number
}```
You can choose specific lines to embed by selecting them before copying the link.
nevermind I figured it out. I should be using
type Opts = {
[P in keyof Foo]: Foo[P]
}
syntax