scdlang
scdlang copied to clipboard
Generate typescript declaration for XState
- [x] ~~assess if serde typescript-definitions crates is suitable~~ the type must be determined before compilation so it can't generate n-number of possible types in a union type ❌
- [x] be06a6d690a71abab2dae107a117f825afaded2c generate Typescript
interface
and uniontype
for State - [x] ~~investigate if serde typescript-definitions can generate
interface
(or atleast plain objecttype
can be treated asinterface
in XState)~~ it can generate type of plain object ✔️ - [x] try to generate typescript declaration from JSON using json_typegen_shared
json_typegen
results
{
"states": {
"set": {
"on": {
"TOGGLE": "reset",
"RESET": "reset",
"OFF": "set"
}
},
"reset": {
"on": {
"TOGGLE": "set",
"SET": "set",
"DATA": "set"
}
}
}
}
json_typegen above.json -O typescript --name MachineConfig > below.ts
interface MachineConfig {
states: States;
}
interface States {
set: Set;
reset: Reset;
}
interface Set {
on: On;
}
interface On {
TOGGLE: string;
RESET: string;
OFF: string;
}
interface Reset {
on: On2;
}
interface On2 {
TOGGLE: string;
SET: string;
DATA: string;
}
Things to keep track
- https://github.com/arabidopsis/typescript-definitions/issues/2
- https://github.com/evestera/json_typegen/issues/10
This is just a temporary hack, in the future find a way to use and contribute to swc_ecma_codegen
typescript implementation. (hint: fork then include that as a git-submodule)
beware: this might need more RAM since Rust langserver doesn't have a mode to conserve memory. So delay this until I can buy better laptop 😢