You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Function types may be written using function type literals or by including call signatures in object type literals. i.e.
<T1,T2, ... >(p1,p2, ... )=>R
is exactly equivalent to the object type literal
{<T1,T2, ... >(p1,p2, ... ) : R}
To differentiate function types defined with object literal, check to see whether the object literal/interface contains a call signature
interfaceA{// an object with a property called `log` which is function typelog(num: number): number;// a property}letobj: A={log(n){returnn;}}interfaceA1{// a function type.(num: number): number// call signature}letfunc: A1=(n: number)=>n
Optional parameters
Optional property can be marked with ? following the parameter name. E.g.
functionparseInt(s: string,radix?: number): number{// ...}letresult1=parseInt('3');// ok letresult2=parseInt('3',2);// okletresult3=parseInt('3',2,'too many');// ok
Functions
Function Types
Function types can be defined in three ways.
Method Signature
Function type literal
Object literal
Function type literal vs Object literal
is exactly equivalent to the object type literal
Optional parameters
Optional property can be marked with
?
following the parameter name. E.g.Overloads
Notice
The text was updated successfully, but these errors were encountered: