typocomath/README.md

52 lines
2.0 KiB
Markdown

# typocomath
A final (?) prototype for a refactor of mathjs, culminating the picomath, pocomath, typomath series. Provides an extensible core with "fuzzy" types for its operations, that can at any time generate exact .d.ts file for its current state.
To build and run the prototype, run:
```
pnpm install
pnpm build-and-run
```
## experiment
Have a look at the section under `/src/experiment` and `/src/plugins`:
- `src/plugins/typeInferPlugin.ts` is the actual plugin
- in `tsconfig.json` we configure TypeScript to run the plugin
- `src/experiment/arithmeticInfer.ts` with an example where we define `__infer__`
- after running TypeScript: look at `build/experiment/arithmeticInfer.ts` where the `__infer__` string literal is replaced with the actual types
### The idea
Create a TypeScript plugin which can replace a string literal like `__infer__` in a typed-function definition:
typed('square', '__infer__', <T>(dep: { ... } => { ... })
with the actual types, something like:
typed('square', '{ deps: { multiply: (a: T, b: T) => T; }; return: (a: T) => T }', <T>(dep: { ... } => { ... })
(We can discuss what syntax we like most, this is just a POC)
### How to run
pnpm build-and-run
### Read more
- https://github.com/microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin
- https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API
- https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#using-the-type-checker
- https://github.com/Microsoft/TypeScript/wiki/Using-the-Language-Service-API
- https://stackoverflow.com/questions/63944135/typescript-compiler-api-how-to-get-type-with-resolved-type-arguments
- https://stackoverflow.com/questions/48886508/typechecker-api-how-do-i-find-inferred-type-arguments-to-a-function
- https://blog.logrocket.com/using-typescript-transforms-to-enrich-runtime-code-3fd2863221ed/
- https://github.com/itsdouges/typescript-transformer-handbook#transforms
### Interesting libraries
- https://github.com/GoogleFeud/ts-macros/
- https://ts-morph.com