|
| 1 | +TypeScript |
| 2 | +========== |
| 3 | + |
| 4 | +esbuild is a real stickler with extensions so it is necessary to require "parser.hera". |
| 5 | +TypeScript then needs a parser.hera.d.ts to work with CoffeeSense. Alternatively |
| 6 | +an esbuild resolver plugin could be used. |
| 7 | + |
| 8 | +So far the clean way of handling it is to declare all the types in `./types/` |
| 9 | +and import then `export = SomeType` in the individual .d.ts files adjacent |
| 10 | +to the sources. |
| 11 | + |
| 12 | +Building with `tsc` is not necessary if we're only using CoffeeScript sources |
| 13 | +since `./types/main.d.ts` is pointed to by the `type` field in `package.json`. |
| 14 | +If there are other TypeScript sources then `tsc` will need to be involved in the |
| 15 | +build process. |
| 16 | + |
| 17 | +`export =` vs `export default` |
| 18 | +--- |
| 19 | + |
| 20 | +`export = Something` is necessary for `Something = require('...')` to get picked |
| 21 | +up properly. `export default Something` works with `{default:Something} = require...` |
| 22 | + |
| 23 | +`export =` cannot be used with `export {something}`. |
| 24 | + |
| 25 | +Since all the modern tools are moving in the direction of ES6 import/export it |
| 26 | +may simplify integration with some tools to also move in that direction. |
| 27 | + |
| 28 | +Ambient Declarations |
| 29 | +--- |
| 30 | + |
| 31 | +A typescript file that exports will ignore ambient `declare` statements. In |
| 32 | +order to have ambient they must all be `declare`. |
| 33 | + |
| 34 | +Ambient declarations also cannot import other types but a work around is to use |
| 35 | +`declare global` and put vars inside there. See [./types/ambient.d.ts](./types/ambient.d.ts) |
| 36 | + |
| 37 | +Namespaces as types |
| 38 | +--- |
| 39 | + |
| 40 | +Cannot use namespace 'Observable' as type. |
| 41 | + |
| 42 | +use `typeof Observable` |
| 43 | + |
| 44 | +TypeDoc |
| 45 | +------- |
| 46 | + |
| 47 | +TypeDoc seems to work pretty good by default when using `.ts` files with ES6 |
| 48 | +style exports. |
| 49 | + |
| 50 | +TypeDoc and other more modern tools strongly prefer ES6 module imports/exports. |
| 51 | +`.d.ts` files prefer it (there is no way to both `export =` and also have named |
| 52 | +exports even if those exports are just types). |
| 53 | + |
| 54 | +JSDoc |
| 55 | +--- |
| 56 | + |
| 57 | +JS written with JSDoc type annotations and compiled with `tsc -d --allowJs` will |
| 58 | +output type declarations. |
| 59 | + |
| 60 | +CoffeeSense + TypeScript |
| 61 | +--- |
| 62 | + |
| 63 | +VSCode Intellisense is the primary documentation target. That means that the |
| 64 | +docs should be optimized for how things appear in the IDE. 2nd target is a |
| 65 | +standalone website generated by TypeDoc or some other tool. Still need to test |
| 66 | +TypeDoc with a .coffee -> .js -> .d.ts -> TypeDoc pipeline and see how it goes. |
| 67 | + |
| 68 | +Need to set `checkJs` to true or add `#@ts-check` to enable type checking in |
| 69 | +CoffeeSense. |
| 70 | + |
| 71 | +It is possible to alias a bunch of imported types at the top to make using |
| 72 | +comments for inline types easier inside the file. |
| 73 | + |
| 74 | +```coffee |
| 75 | +###* |
| 76 | +@typedef {import("../types/types").Element} El |
| 77 | +@typedef {import("../types/types").Context} Context |
| 78 | +@typedef {import("../types/types").JadeletAttribute} JadeletAttribute |
| 79 | +@typedef {import("../types/types").JadeletAST} JadeletAST |
| 80 | +### |
| 81 | +``` |
0 commit comments