glideapps / glideapps/quicktype

(JavaScript/TypeScript target) Runtime parsing assigns `undefined` values

Open
#1,781 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
13.9k
Forks
1.2k
Avg merge
8h 53m
Merged PRs (30d)
369

Description

When targeting ts/js from JSON schema runtime parser assigns `undefiend` values if value isn't present in input and wasn't required in schema. I found this behaviour very annoying, because it would just spam console with `undefined` values.

Here is example (if needed):
```json
{
"$schema": "http://json-schema.org/draft-07/schema",
"title": "demo",
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
}
```
```console
quicktype schema.json -s schema -o out.js
```
```js
// @filename main.js
import { toOut } from './out.js'

console.log(toOut('{}'))
//=> { name: undefined }
```

I think we can probably simplify generated code for runtime parsing.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.