i'm trying to use the keyof keyword in typescript
but it seems to be not found.
I'm using typescript 3.5.2
with angular 7.2.2
Thanks in advance.
export class Functions {
static ListObjectProperties(): string[] {
let array = keyof Foo;
return array;
}
}
I get "Cannot find name 'keyof'"
keyof is a keyword in TypeScript which is used to extract the key type from an object type.
The extends keyword is used to apply constraints to K, so that K is one of the string literal types only. extends means “is assignable” instead of “inherits”' K extends keyof T means that any value of type K can be assigned to the string literal union types.
You can only use keyof
in a type context.
For instance:
interface Foo { aProperty: unknown }
const x: keyof Foo = "aProperty"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With