DrSensor / DrSensor/scdlang

Generate typescript declaration for XState

Open
#17 1 comment 0 reactions 1 assignee Claimed by @DrSensor View on GitHub
enhancement good first issue
Dominant language
Rust
Stars
103
Forks
2
PR merge metrics
No merged PRs in 30d

Description

- [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 union `type` for State](https://xstate.js.org/docs/guides/typescript.html)
- [x] ~~investigate if [serde typescript-definitions][] can generate `interface` (or atleast plain object `type` can be treated as `interface` in XState)~~ it can generate type of plain object ✔️
- [x] try to generate typescript declaration from JSON using [json_typegen_shared](https://docs.rs/json_typegen_shared/0.3.2/json_typegen_shared/fn.codegen.html)
json_typegen results

```json
{
"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`
```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

[serde typescript-definitions]: https://github.com/arabidopsis/typescript-definitions

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.