TypeScript语法中有哪些操作符?

535 ℃

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);

一款快速开发后中后台系统框架——Bag-Admin

typescript参数名后面的问号是什么意思?

vue3相对于vue2有哪些新特性?

typescript语法中is关键字是做什么的?

简单介绍一下什么是TS的应用(vue开发)

标签: ts操作符, typescript

上面是“TypeScript语法中有哪些操作符?”的全面内容,想了解更多关于 vuejs 内容,请继续关注web建站教程。

当前网址:https://m.ipkd.cn/webs_3864.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

帝国cms如何统计某个数据表里有多少文章
php伪静态页面如何隐藏php后缀
html语法中有哪些空格代码
vuejs生命周期的8个阶段
对比SEO技术和营销,哪个起主导作用?