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

Java知识分享网

Java1234官方群25:java1234官方群17
Java1234官方群25:838462530
        
SpringBoot+SpringSecurity+Vue+ElementPlus权限系统实战课程 震撼发布        

最新Java全栈就业实战课程(免费)

springcloud分布式电商秒杀实战课程

IDEA永久激活

66套java实战课程无套路领取

锋哥开始收Java学员啦!

Python学习路线图

锋哥开始收Java学员啦!

learning typescript PDF 下载


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

 
相关截图:
 

主要内容:

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.

 


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

锋哥公众号


锋哥微信


关注公众号
【Java资料站】
回复 666
获取 
66套java
从菜鸡到大神
项目实战课程

锋哥推荐