Java知识分享网 - 轻松学习从此开始!    

Java知识分享网

        

联系锋哥QQ:3320160706

AI编程,程序员挑战年入30~100万高级指南 - 职业规划
Java、Python项目定制,修改,毕设辅导找 Java1234_小锋老师,专业又靠谱。   锋哥QQ:3320160706   锋哥微信:java9579

learning typescript PDF 下载


时间:2024-02-09 11:26来源:http://www.java1234.com 作者:转载  侵权举报
learning typescript
失效链接处理
learning typescript PDF 下载

转载自:
提取码:spgf
 
相关截图:
 

主要内容:

Type declarations
You can add type declarations to variables, function parameters and function return types. The
type is written after a colon following the variable name, like this: var num: number = 5; The
compiler will then check the types (where possible) during compilation and report type errors.


var num: number = 5;
num = "this is a string"; // error: Type 'string' is not assignable to type 'number'.

 

The basic types are :
number (both integers and floating point numbers)
•
string
•
boolean
•
Array. You can specify the types of an array's elements. There are two equivalent ways to
define array types: Array<T> and T[]. For example:
number[] - array of numbers
○
Array<string> - array of strings
○
•
Tuples. Tuples have a fixed number of elements with specific types.
[boolean, string] - tuple where the first element is a boolean and the second is a
string.
○
[number, number, number] - tuple of three numbers.
○
•
{} - object, you can define its properties or indexer
•
https://riptutorial.com/
6
{name: string, age: number} - object with name and age attributes
○
{[key: string]: number} - a dictionary of numbers indexed by string
○
enum - { Red = 0, Blue, Green } - enumeration mapped to numbers
•
Function. You specify types for the parameters and return value:
(param: number) => string - function taking one number parameter returning string
○
() => number - function with no parameters returning an number.
○
(a: string, b?: boolean) => void - function taking a string and optionally a boolean with
no return value.
○
•
any - Permits any type. Expressions involving any are not type checked.
•
void - represents "nothing", can be used as a function return value. Only null and undefined
are part of the void type.
•
never
let foo: never; -As the type of variables under type guards that are never true.
○
function error(message: string): never { throw new Error(message); } - As the return
type of functions that never return.
○
•
null - type for the value null. null is implicitly part of every type, unless strict null checks are
enabled.

 


------分隔线----------------------------


锋哥推荐