typescript underlying type 02

 // JavaScript enumerated type to a standard data types can also be a handy addition to your enumerated type value of the specified members of the manual is that you can provide a worthwhile enumeration to its name. 
 // For example, we know that the value is 2, but not sure it is mapped to the Color in which the name, we can find the appropriate name:
 enum x{
     up=1,
     down,
     left,
     right
 }

 

let  where = x.down;
let where2=x[2];

 

 // any type any type of value you can specify the type of a variable of type is unclear
  let  a:any='5454'
  a=555
  a=[1,2,3];




 // void; type two undefined null value 
 // To some extent, void of any type such as the type of contrast, it does not represent any kind. When a function does not return a value, you will usually see its return value type is void:

 

 let not:void=undefined;
 let not2:void=null;

 

 // Null and Undefined type
 // TypeScript in both undefined and null, respectively, each have their own type, called undefined and null. And void similar to their own type is not very useful:
 let u:undefined=undefined;
 let n:null=null;

 

 // - strictNullChecks marker may detect data type void null, undefined



 // never type indicates the type of value that will never exist. 
 // For example, never type are those that always throws an exception or does not have a function that returns the expression or function of the value of the expression arrow return type; variable may also be a type never, never be true when they are when the type of protection apply.
 
 
 // function never returns the end point must exist can not be achieved
function error(message: string): never {
    throw new Error(message);
}

 

// inferred return type is never
function fail() {
    return error("Something failed");
}

 

// function never returns the end point must exist can not be achieved
function infiniteLoop(): never {
    while (true) {
    }
}

 

// type of assertion
// Sometimes you will encounter such a situation, you will know more about the details of a value than TypeScript. Usually this will happen to you clearly know that an entity has more precise than its existing type of type.

 

let num:any='every day';
// The first way to write the angle brackets wording
let num1:number=(<string>num).length

 

// The second written as
let num2:number=(num as string).length;



Guess you like

Origin www.cnblogs.com/duanyiwen/p/11795593.html