函数参数和返回值中的类型。字符串
例:
function hello(name: string): string {
return `Hello ${name}!`;
}
这里的语法 name: string
意味着该函数可以接受一个 name
参数,这个参数只能是字符串而 (...): string {
意味着返回值只能是一个字符串
用法:
hello('StackOverflow Documentation') // will be return Hello StackOverflow Documentation!