Check out this demo
You can also try it in the sandbox
See how the code works:
type FunctionPropertyNames<T> = {
[K in keyof T]: T[K] extends Function ? K : never;
}[keyof T];
interface Part {
id: number;
name: string;
subparts: Part[];
updatePart(newName: string): void;
}
type T1 = FunctionPropertyNames<Part>;
const myVar:T1 = 'updatePart'
I'm puzzled by the [keyof T]
part in
type FunctionPropertyNames<T> = {...}[keyof T]
. It's a unique syntax I haven't encountered before and couldn't find much about it in the resources. Can you show me another instance of its application? Or direct me to where I can learn more about it. Maybe shed some light on how it functions.
Your assistance is greatly appreciated!