Typescript 参数名称中的问号是什么 [英] What is the question mark for in a Typescript parameter name
本文介绍了Typescript 参数名称中的问号是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
export class Thread {
id: string;
lastMessage: Message;
name: string;
avatarSrc: string;
constructor(id?: string,
name?: string,
avatarSrc?: string) {
this.id = id || uuid();
this.name = name;
this.avatarSrc = avatarSrc;
}
}
id?
中的 ?
是干什么用的?
In id?
what's the ?
for?
推荐答案
就是将参数标记为可选.
- TypeScript 手册 https://www.typescriptlang.org/docs/handbook/2/functions.html#optional-parameters
- TypeScript 深入探讨 https://basarat.gitbook.io/typescript/type-system/functions#optional-parameters
这篇关于Typescript 参数名称中的问号是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文