TypeScript 字面量类型

先看两端代码

let str = "hello"
const str1:string = "hello"
const str2 = "hello"

在上述代码中用let声明的变量是字符类型的

而用const 没有指定类型的话,其是字面量类型,不能随意进行变更。

 

posted @ 2024-09-29 22:38  洛飞  阅读(2)  评论(0编辑  收藏  举报