Skip to content

Commit 7560952

Browse files
authored
fix: avoid incorrect additionalProperties for Pick<..., AliasLiteralUnion> (#2230)
1 parent 9173fa1 commit 7560952

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

src/NodeParser/MappedTypeNodeParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export class MappedTypeNodeParser implements SubNodeParser {
158158
keyListType: UnionType,
159159
context: Context,
160160
): BaseType | boolean {
161-
const key = keyListType.getTypes().filter((type) => !(type instanceof LiteralType))[0];
161+
const key = keyListType.getTypes().filter((type) => !(derefType(type) instanceof LiteralType))[0];
162162

163163
if (key) {
164164
return (

test/valid-data-type.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ describe("valid-data-type", () => {
8888
it("type-keyof-tuple", assertValidSchema("type-keyof-tuple", "MyType"));
8989
it("type-keyof-object", assertValidSchema("type-keyof-object", "MyType"));
9090
it("type-keyof-object-function", assertValidSchema("type-keyof-object-function", "MyType"));
91+
it("type-mapped-pick-union-alias", assertValidSchema("type-mapped-pick-union-alias", "PickAliasedLiteralUnion"));
9192
it("type-mapped-simple", assertValidSchema("type-mapped-simple", "MyObject"));
9293
it("type-mapped-index", assertValidSchema("type-mapped-index", "MyObject"));
9394
it("type-mapped-index-as", assertValidSchema("type-mapped-index-as", "MyObject"));
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
interface SomeInterface {
2+
foo: string;
3+
bar: number;
4+
}
5+
6+
type KeyFoo = "foo";
7+
type KeyBar = "bar";
8+
9+
export type PickAliasedLiteralUnion = Pick<SomeInterface, KeyFoo | KeyBar>;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"$ref": "#/definitions/PickAliasedLiteralUnion",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"definitions": {
5+
"PickAliasedLiteralUnion": {
6+
"additionalProperties": false,
7+
"properties": {
8+
"bar": {
9+
"type": "number"
10+
},
11+
"foo": {
12+
"type": "string"
13+
}
14+
},
15+
"required": [
16+
"foo",
17+
"bar"
18+
],
19+
"type": "object"
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)