目次
number
let year: number = 2000
// year = false
// error TS2322: Type 'boolean' is not assignable to type 'number'.
console.log(year)
let age: number = 0x2b
string
let name: string = "田中"
// name = 10
// error TS2322: Type 'number' is not assignable to type 'string'.
console.log(name)
boolean
let isFinished: boolean = true
isFinished = false
// isFinished = 1
// error TS2322: Type 'number' is not assignable to type 'boolean'.
console.log({ isFinished })
void
// いかなる返り値も持たないことを明示
function returnNothing(): void {
console.log("don't return anything")
}
console.log(returnNothing())
null
// nullのみ
let absence: null = null
// absence = "moji"
// error TS2322: Type '"moji"' is not assignable to type 'null'.
undefined
// undefinedのみ
let data: undefined = undefined
// data = 329
// error TS2322: Type '329' is not assignable to type 'undefined'.
any
// いかなる値もエラーはなし
let year: any = 2000
// year = false
// エラーなし
console.log(year)