zl程序教程

您现在的位置是:首页 >  其他

当前栏目

TypeScript重点知识点说明

知识点typescript 说明 重点
2023-09-27 14:25:59 时间
  • 两个模块之间的关系是通过在文件级别上使用importexport建立的。

  • 任何包含顶级import或者export的文件都被当成一个模块。相反,如果一个文件不带有顶级的import或者export声明,那么它的内容被视为全局可见的

  • 可选参数的函数声明:function functionName(param1: type, param2?: type) : type ,可选参数必须跟在必须参数后面,举例如下

function buildName(firstName: string, lastName?: string):string {
    if (lastName)
        return firstName + " " + lastName;
    else
        return firstName;
}

let result1 = buildName("Bob");  // works correctly now
let result2 = buildName("Bob", "Adams", "Sr.");  // error, too many parameters
let result3 = buildName("Bob", "Adams");  // ah, just right
  • 可变参数的函数声明:function functionName(param1: type, ...param: type[]) : type
function buildName(firstName: string, ...restOfName: string[]) {
 return firstName + " " + restOfName.join(" ");
}

let employeeName = buildName("Joseph", "Samuel", "Lucas", "MacKinzie");