在vs code 开发工具中命令行输入:
第一种用法: 分开输入。先输入 tsc 文件名称.ts
; 然后再输入 node 文件名称.js
;
第二种用法: 使用&&
一次输入。 tsc 文件名称.ts; && node 文件名称.js
.
TypeScript 通过 tsc 文件名称.ts 命令编译生成 JavaScript ,然后使用命令: node 文件名称.js
类型
错误用法:
function print(str:string){
if(typeof(str)=="string"){
console.log(str);
}
}
print(124); //编写中就提示错误
print("123ts")
如果出现如下错误:
- Overload signature is not compatible with function implementation. 重载签名与函数实现不兼容。如代码:declare function print(): void;(翻译:声明函数print() 无效的.)
- Overload signatures must all be ambient or non-ambient. 重载签名必须全部为环境或非环境。
- Argument of type ‘1234’ is not assignable to parameter of type ‘string’. “1234”类型的参数不能分配给“string”类型的参数。
解决方案:
- 更改函数名称:print() -> pr