-
Notifications
You must be signed in to change notification settings - Fork 235
fix: dereference alias types in discriminated unions (#1750) #2420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import { assertValidSchema } from "../../utils"; | ||
| import { test } from "node:test"; | ||
|
|
||
| test("dereference-alias-types-discriminated-unions", assertValidSchema("dereference-alias-types-discriminated-unions", "MyUnion")); |
|
arthurfiorette marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| type KindA = "kind_a"; | ||
| type KindB = "kind_b"; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what happens if you export KindB? will it keep being a reference instead of inlining like {
"const": "kind_a",
"type": "string"
},? |
||
|
|
||
| interface ObjectA { | ||
| kind: KindA; | ||
| value: number; | ||
|
arthurfiorette marked this conversation as resolved.
|
||
| } | ||
|
|
||
| interface ObjectB { | ||
| kind: KindB; | ||
| name: string; | ||
| } | ||
|
|
||
| export type MyUnion = ObjectA | ObjectB; | ||
|
Comment on lines
+13
to
+14
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| { | ||
| "$ref": "#/definitions/MyUnion", | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
| "definitions": { | ||
| "MyUnion": { | ||
| "anyOf": [ | ||
| { | ||
|
Comment on lines
+5
to
+7
|
||
| "additionalProperties": false, | ||
| "properties": { | ||
| "kind": { | ||
| "const": "kind_a", | ||
| "type": "string" | ||
| }, | ||
| "value": { | ||
| "type": "number" | ||
| } | ||
| }, | ||
| "required": [ | ||
| "kind", | ||
| "value" | ||
| ], | ||
| "type": "object" | ||
| }, | ||
| { | ||
| "additionalProperties": false, | ||
| "properties": { | ||
| "kind": { | ||
| "const": "kind_b", | ||
| "type": "string" | ||
| }, | ||
| "name": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "required": [ | ||
| "kind", | ||
| "name" | ||
| ], | ||
| "type": "object" | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.