跳到主要内容

Typescript

npm add -D typescript@latest

tsc --noEmit # check syntax
tsc --pretty --noEmit # pretty output

npx typesync # 自动添加 @types/ 依赖

# 使用 typing 类型
# typings install dt~node dt~express dt~body-parser dt~serve-static dt~express-serve-static-core dt~mime --global
# 使用模块定义类型
# npm add @types/{node,express,body-parser,serve-static,express-serve-static-core,mime}

# 单个文件
npx tsc --out test.js ./src/test.ts --module system

NPM 模块开发

  • 生成配置文件
yarn init -y
yarn add typescript -D
yarn run tsc -- --init
  • 修改 tsconfig.json 的输出目录为 dist
  • package.json 中添加相关信息即可
  "main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"prepublish": "npm run build",
"build": "tsc"
},

ts-node

FAQ

引用全局对象

const AMap = (window as any)['AMap'];

Dec

https://codeburst.io/decorate-your-code-with-typescript-decorators-5be4a4ffecb4 https://itnext.io/extracting-decorated-properties-from-classes-in-typescript-caf24aabcb59

Request: Class Decorator Mutation https://github.com/Microsoft/TypeScript/issues/4881

https://www.typescriptlang.org/docs/handbook/decorators.html