Typescript
约 1 分钟阅读
- www.typescriptlang.org
- declaration-files introduction
- DefinitelyTypedGitHubDefinitelyTyped/DefinitelyTyped
- 中文手册
- typingsGitHubtypings/typings
- Playground
- NOTES
- 接口不能做反射
export default不能有类型定义 #13626GitHub IssueMicrosoft/TypeScript#13626
- json2ts
- JSON 转接口定义
- 也可以自己写代码转, 参考这里
- Advanced Types
- 辅助定义类型的类型定义
- Partial
- 所有字段可为 null
- Readonly
- 所有字段只读
- Pick
- 从一个类型中选择部分字段
- Record
Record<'prop1' | 'prop2' | 'prop3', string>- 定义有三个 string 类型字段的类型
- tsdoc.org
- 参考
- 注意
abstract方法不会在 prototype 里,不会生成任何内容,只是类型校验
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
# 查看所有文件
# --explainFiles 显示包含原因
npx tsc --listFiles --noEmit --noCheck依赖包typescriptnpm 包typescriptNPM
NPM 模块开发
- 生成配置文件
yarn init -y
yarn add typescript -D
yarn run tsc -- --init依赖包typescriptnpm 包typescriptNPM
- 修改
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
codeburst.io/decorate-your-code-with-typescript-decorators-5be4a4ffecb4 itnext.io/extracting-decorated-properties-from-classes-in-typescript-caf24aabcb59
Request: Class Decorator Mutation Microsoft/TypeScript#4881GitHub IssueMicrosoft/TypeScript#4881
关联信息
反向链接、本文链接的其他页面和外部资料。
参考资料
GitHub5 条
- DefinitelyTyped/DefinitelyTypedgithub.com/DefinitelyTyped/DefinitelyTyped
- Microsoft/TypeScript#13626github.com/Microsoft/TypeScript/issues/13626
- Microsoft/TypeScript#4881github.com/Microsoft/TypeScript/issues/4881
- typescript-cheatsheets/react-typescript-cheatsheetgithub.com/typescript-cheatsheets/react-typescript-cheatsheet
- typings/typingsgithub.com/typings/typings
其他外链12 条
- codeburst.io/decorate-your-code-with-typescript-decorators-5be4a4ffecb4codeburst.io/decorate-your-code-with-typescript-decorators-5be4a4ffecb4
- itnext.io/extracting-decorated-properties-from-classes-in-typescript-caf24aabcb59itnext.io/extracting-decorated-properties-from-classes-in-typescript-caf24aabcb59
- json2ts.comjson2ts.com/
- stackoverflow.com/a/41071619/1870054stackoverflow.com/a/41071619/1870054
- tsdoc.orgtsdoc.org/
- www.typescriptlang.orgwww.typescriptlang.org/
- www.typescriptlang.org/docs/handbook/advanced-types.htmlwww.typescriptlang.org/docs/handbook/advanced-types.html
- www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.htmlwww.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html
- www.typescriptlang.org/docs/handbook/declaration-files/introduction.htmlwww.typescriptlang.org/docs/handbook/declaration-files/introduction.html
- www.typescriptlang.org/docs/handbook/decorators.htmlwww.typescriptlang.org/docs/handbook/decorators.html
- www.typescriptlang.org/playwww.typescriptlang.org/play
- zhongsp.gitbooks.io/typescript-handbookzhongsp.gitbooks.io/typescript-handbook