Skip to content

Commit

Permalink
Add test, use uniqueTypeArray
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Apr 21, 2024
1 parent 47af8b9 commit 512274d
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/NodeParser/MappedTypeNodeParser.ts
Expand Up @@ -18,6 +18,7 @@ import { derefAnnotatedType, derefType } from "../Utils/derefType.js";
import { getKey } from "../Utils/nodeKey.js";
import { preserveAnnotation } from "../Utils/preserveAnnotation.js";
import { removeUndefined } from "../Utils/removeUndefined.js";
import { uniqueTypeArray } from "../Utils/uniqueTypeArray.js";

export class MappedTypeNodeParser implements SubNodeParser {
public constructor(
Expand Down Expand Up @@ -102,8 +103,7 @@ export class MappedTypeNodeParser implements SubNodeParser {
}

protected getProperties(node: ts.MappedTypeNode, keyListType: UnionType, context: Context): ObjectProperty[] {
return keyListType
.getFlattenedTypes(derefType)
return uniqueTypeArray(keyListType.getFlattenedTypes(derefType))
.filter((type): type is LiteralType => type instanceof LiteralType)
.map((type) => [type, this.mapKey(node, type, context)])
.filter((value): value is [LiteralType, LiteralType] => value[1] instanceof LiteralType)
Expand Down
9 changes: 0 additions & 9 deletions src/Utils/uniqueArray.ts

This file was deleted.

1 change: 1 addition & 0 deletions test/valid-data-type.test.ts
Expand Up @@ -102,6 +102,7 @@ describe("valid-data-type", () => {
it("type-mapped-additional-props", assertValidSchema("type-mapped-additional-props", "MyObject"));
it("type-mapped-array", assertValidSchema("type-mapped-array", "MyObject"));
it("type-mapped-union-intersection", assertValidSchema("type-mapped-union-intersection", "MyObject"));
it("type-mapped-union-union", assertValidSchema("type-mapped-union-union", "MyType"));
it("type-mapped-enum", assertValidSchema("type-mapped-enum", "MyObject"));
it("type-mapped-enum-optional", assertValidSchema("type-mapped-enum-optional", "MyObject"));
it("type-mapped-enum-null", assertValidSchema("type-mapped-enum-null", "MyObject"));
Expand Down
File renamed without changes.

0 comments on commit 512274d

Please sign in to comment.