Skip to content

基础类型与对象类型

js
// // 基础类型 number、string、null、undefined、symbol、boolean、void等
let num: number = 1
let str: string = '1'
let chaos: number | string = 'chaos'
let nl: null = null
let undef: undefined = undefined
// let e: symbol = Symbol()
let boo: boolean = true
let vo: void = null // unll 或者 undefined

// // 对象类型
const obje: {a: number, b: string} = {a: 1, b: ''}
const arr: number[] = [1, 2, 3]
class Person {}
const Chaos: Person = new Person() // Chaos的类型为一个类
const func: () => number = function(){return 1} // fn是一个返回值类型为number的函数