2022-12-02 14:04:53 +00:00
# typocomath
2023-01-22 01:34:57 +00:00
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:
```
2023-01-25 13:42:23 +00:00
pnpm install
pnpm build-and-run
2023-01-22 01:34:57 +00:00
```
2023-03-14 08:51:28 +00:00
## experiment
2023-09-01 16:21:45 +00:00
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__`
2023-09-01 16:36:50 +00:00
- after running TypeScript: look at `build/experiment/arithmeticInfer.ts` where the `__infer__` string literal is replaced with the actual types
2023-03-14 08:51:28 +00:00
### The idea
2023-09-01 16:21:45 +00:00
Create a TypeScript plugin which can replace a string literal like `__infer__` in a typed-function definition:
2023-03-14 08:51:28 +00:00
2023-09-01 16:21:45 +00:00
typed('square', '__infer__', < T > (dep: { ... } => { ... })
2023-03-14 08:51:28 +00:00
2023-09-01 16:21:45 +00:00
with the actual types, something like:
2023-03-14 08:51:28 +00:00
2023-09-01 16:21:45 +00:00
typed('square', '{ deps: { multiply: (a: T, b: T) => T; }; return: (a: T) => T }', < T > (dep: { ... } => { ... })
2023-03-14 08:51:28 +00:00
2023-09-01 16:21:45 +00:00
(We can discuss what syntax we like most, this is just a POC)
2023-03-14 08:51:28 +00:00
### How to run
2023-09-01 16:21:45 +00:00
pnpm build-and-run
2023-03-14 08:51:28 +00:00
### 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
2023-03-14 09:15:56 +00:00
- 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/
2023-08-18 15:39:57 +00:00
- https://github.com/itsdouges/typescript-transformer-handbook#transforms
2023-09-01 15:52:44 +00:00
### Interesting libraries
- https://github.com/GoogleFeud/ts-macros/
- https://ts-morph.com