var a = {
b:null,
}
I want to specify that the type of a.b
is (num:number) => void
while still setting it to null
.
Is it possible to do without using class or interface?
This should work:
let a = {
b: <(number) => void> null
};
Or you can use a type declaration to make your special function explicit:
declare type MyFun = (number) => void;
let a = {
b: <MyFun> null
};
Although it's not necessary, I tend to make use of type declarations in my code when there the function has semantics that is not easily caught in the type signature, but can be specified easily in a name.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments