wrap in an init

This commit is contained in:
Brian Hicks 2024-04-10 06:17:36 -05:00
parent 514716e9b3
commit 2418f94b58
No known key found for this signature in database
GPG Key ID: C4F324B9CAAB0D50
4 changed files with 25 additions and 5 deletions

View File

@ -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
```

View File

@ -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)

View File

@ -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)]

View File

@ -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
```