Working with typescript
Editor integration
You should consider installing a suitable set of extensions for Typescript based on your editor. Here are some features that you probably want to make your TS development experience much smoother:
- Inline errors
- Type documentation tooltips
- Suggestions & Fix Problem
- ESlint support
- Jump to Definition & Find Usages
- Rename symbol
Suggestions:
- VSCode: VSCode has built-in TS support, however you should also get the
ESLint(byDirk Baeumer) extension. - Atom:
atom-typescriptplugin. - Sublime Text: use the
TypeScriptpackage.
If you use another editor, look for an extension that supports Typescript via the language server protocol - this is a standard interface via which TS and other languages provide IDE-like functionality to editors, and it means you'll get support for the latest TS features immediately rather than waiting for a plugin author to support them.
Global types
Define global types in src/types.d.ts.
Global type should be defined sparingly. Only the objects that are used again and again across dozens of files, and which have no other logical home other than as "business objects" specific to your project, should be considered as global types. Otherwise you should just define and import/export types where they are needed.
types.d.ts is not for shims, quick-fixes, etc.The global types defined in types.d.ts should be the "business objects" used in your themes - the core logical types of objects used across the whole project, or "utility types" - generic functional types which can be used to simplify the expression of more complex types.
Don't use global types to define shims or poorly thought out types.
// TODO: what are actual valid use cases for this in theme builds?