david2tdw / blog

学习记录
1 stars 1 forks source link

[typescript] TypeScript 命令相关 #169

Open david2tdw opened 4 years ago

david2tdw commented 4 years ago

初始化一个typescript项目:

C:\Users\RS\Desktop\test\vue\typescript>tsc --init
message TS6071: Successfully created a tsconfig.json file.
david2tdw commented 4 years ago

编译并执行ts文件:

base-type.ts

let name: string = 'tdw'
let age: number = 12
let sen: string = `hello , my name is ${name}, i will be ${age + 1} years `

console.log(sen + name)

export {}

代码中添加export {}的原因: 如何在typescript中解决 error TS2451: Cannot redeclare block-scoped variable 'name'

执行:

C:\Users\RS\Desktop\test\vue\typescript>ts-node base-type.ts
hello , my name is tdw, i will be 13 years tdw