美文网首页
hello typescript

hello typescript

作者: 暖年的咆哮 | 来源:发表于2019-10-15 17:06 被阅读0次
npm install -g typescript

新建一个hello.ts文件

function hello(person:string) { //函数参数这里,必须指定传入的参数是什么类型,否则编译会报错,但是仍然会继续编译
    return 'hello' + person
}
let username = '大狗'
console.log(hello(username))

TypeScript 中,使用 : 指定变量的类型,: 的前后有没有空格都可以

运行

tsc hello.ts

会生成一个hello.js文件

function hello(person) {
    return 'hello' + person;
}
var username = '大狗';
console.log(hello(username));

TypeScript 编译的时候即使报错了,还是会生成编译结果,我们仍然可以使用这个编译之后的文件。

相关文章

网友评论

      本文标题:hello typescript

      本文链接:https://www.haomeiwen.com/subject/jqismctx.html