typocomath/README.md

62 lines
1.9 KiB
Markdown
Raw Normal View History

2022-12-02 14:04:53 +00:00
# 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:
```
2023-01-25 13:42:23 +00:00
pnpm install
pnpm build-and-run
```
2023-03-14 08:51:28 +00:00
## experiment
See: the section under `/src/experiment` and `/src/plugins`.
### The idea
Create a TypeScript plugin which can replace structures like:
infer(factoryFunction)
where `factoryFunction` is a mathjs factory function in TypeScript, with something like:
infer({ signature: factoryFunction })
where `signature` is a string containing the type of the factory function and its dependencies.
Relevant methods of the TypeScript compiler are:
```ts
const program = ts.createProgram(fileNames, options)
const typeChecker = program.getTypeChecker()
// relevant methods:
//
// typeChecker.getSymbolAtLocation
// typeChecker.getTypeOfSymbolAtLocation
// typeChecker.getResolvedSignature
// typeChecker.getSignaturesOfType
```
### Status
None of the experiments (`infer1` and `infer2`) are outputting something useful yet.
### How to run
pnpm experiment:infer1
pnpm experiment:infer1-direct
pnpm experiment:infer2
### 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/