
TypeScript语法所用的操作符分别是可选链操作符、非空断言操作符、明确类型断言、空合并操作符和明确类型转换?下面web建站小编给大家简单各种操作符的基本运用!
可选链操作符
interface Person {
name: string;
address?: {
city: string;
};
}
const person: Person = {
name: "John",
};
const city = person.address?.city;
非空断言操作符
const element: HTMLElement | null = document.getElementById("my-element");
const width: number = element!.offsetWidth;
明确类型断言
const input: unknown = "27"; const value: number = <number>(<string>input).length;
空合并操作符
const value: number | null = null; const defaultValue = 27; const result = value ?? defaultValue;
明确类型转换
const value: string = "27"; const numberValue: number = Number(value);
标签: ts操作符, typescript
上面是“TypeScript语法中有哪些操作符?”的全面内容,想了解更多关于 vuejs 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_3864.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

uniapp语法如何禁止view手动滑动
Speakr:自动化完成会议录音转写、内容摘要提炼与智能问答等功能
推荐一个数字宝库——Internet Archive(互联网档案馆)
鼠标测试大师官网:一个专业的鼠标性能测试工具
git教程之SourceTree使用介绍,附官网下载链接