mirror of
https://github.com/BrianHicks/elm-duet.git
synced 2024-09-11 13:45:23 +03:00
wrap in an init
This commit is contained in:
parent
514716e9b3
commit
2418f94b58
@ -47,9 +47,12 @@ You can generate code from this like so:
|
||||
$ elm-duet examples/jwt_schema.json
|
||||
// Warning: this file is automatically generated. Don't edit by hand!
|
||||
|
||||
{
|
||||
(config: {
|
||||
flags: {
|
||||
currentJwt: string;
|
||||
}
|
||||
};
|
||||
node: HTMLElement;
|
||||
}): void
|
||||
|
||||
```
|
||||
|
||||
|
@ -30,7 +30,7 @@ impl Schema {
|
||||
.wrap_err("could not interpret JTD schema for flags")?;
|
||||
|
||||
buffer.push('\n');
|
||||
buffer.push_str(&typescript::TSType::from_schema(flags).to_source())
|
||||
buffer.push_str(&typescript::TSType::from_schema(flags).to_init().to_source())
|
||||
}
|
||||
|
||||
Ok(buffer)
|
||||
|
@ -81,6 +81,20 @@ impl TSType {
|
||||
fn new_function(args: BTreeMap<String, TSType>) -> Self {
|
||||
Self::FunctionReturningVoid(args)
|
||||
}
|
||||
|
||||
fn new_init(flags: TSType) -> Self {
|
||||
Self::new_function(BTreeMap::from([(
|
||||
"config".to_string(),
|
||||
Self::Object(BTreeMap::from([
|
||||
("node".to_string(), Self::Scalar("HTMLElement")),
|
||||
("flags".to_string(), flags),
|
||||
])),
|
||||
)]))
|
||||
}
|
||||
|
||||
pub fn to_init(self) -> Self {
|
||||
Self::new_init(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -6,9 +6,12 @@ You can generate TypeScript types like this:
|
||||
$ elm-duet tests/schema.json
|
||||
// Warning: this file is automatically generated. Don't edit by hand!
|
||||
|
||||
{
|
||||
(config: {
|
||||
flags: {
|
||||
currentTimeMillis: number;
|
||||
notificationPermission: "default" | "denied" | "granted";
|
||||
}
|
||||
};
|
||||
node: HTMLElement;
|
||||
}): void
|
||||
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user