-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: go back to generating enums out of unions containing enums (#2149)
Co-authored-by: Arthur Fiorette <[email protected]>
- Loading branch information
1 parent
2f097ef
commit ddd2d2c
Showing
8 changed files
with
428 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,3 @@ | ||
export function uniqueArray<T>(array: readonly T[]): T[] { | ||
return array.reduce((result: T[], item: T) => { | ||
if (!result.includes(item)) { | ||
result.push(item); | ||
} | ||
|
||
return result; | ||
}, []); | ||
return array.filter((value, index) => array.indexOf(value) === index); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
enum Alphabet { | ||
Alpha = "alpha", | ||
Beta = "beta", | ||
Omega = 666, | ||
} | ||
|
||
enum FileAccess { | ||
None = 0, | ||
Read = 1 << 1, | ||
Write = 1 << 2, | ||
ReadWrite = Read | Write, | ||
} | ||
|
||
export type MyObject = { | ||
// All the members above should be output as enums, not anyOf | ||
enumMembers: Alphabet.Alpha | Alphabet.Beta; | ||
enumMemberWithLiteral: Alphabet.Alpha | "foo"; | ||
enumMemberWithLiteralAndNull: Alphabet.Alpha | "foo" | null; | ||
enumMemberWithInterface: Alphabet.Alpha | { abc: string }; | ||
enumMembersWithNumber: Alphabet.Alpha | Alphabet.Omega; | ||
wholeEnum: Alphabet; // Should output just all of Alphabet | ||
wholeEnumWithLiteral: Alphabet | "bar"; // Should output all of Alphabet members (2 strings, 1 number) and "bar" | ||
wholeEnumWithLiteralAndNull: Alphabet | "bar" | null; | ||
twoDifferentEnumMembers: Alphabet.Alpha | FileAccess.Read; | ||
twoDifferentWholeEnums: Alphabet | FileAccess; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
{ | ||
"$ref": "#/definitions/MyObject", | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"definitions": { | ||
"MyObject": { | ||
"additionalProperties": false, | ||
"properties": { | ||
"enumMemberWithInterface": { | ||
"anyOf": [ | ||
{ | ||
"const": "alpha", | ||
"type": "string" | ||
}, | ||
{ | ||
"additionalProperties": false, | ||
"properties": { | ||
"abc": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"abc" | ||
], | ||
"type": "object" | ||
} | ||
] | ||
}, | ||
"enumMemberWithLiteral": { | ||
"enum": [ | ||
"alpha", | ||
"foo" | ||
], | ||
"type": "string" | ||
}, | ||
"enumMemberWithLiteralAndNull": { | ||
"enum": [ | ||
"alpha", | ||
"foo", | ||
null | ||
], | ||
"type": [ | ||
"string", | ||
"null" | ||
] | ||
}, | ||
"enumMembers": { | ||
"enum": [ | ||
"alpha", | ||
"beta" | ||
], | ||
"type": "string" | ||
}, | ||
"enumMembersWithNumber": { | ||
"enum": [ | ||
"alpha", | ||
666 | ||
], | ||
"type": [ | ||
"string", | ||
"number" | ||
] | ||
}, | ||
"twoDifferentEnumMembers": { | ||
"enum": [ | ||
"alpha", | ||
2 | ||
], | ||
"type": [ | ||
"string", | ||
"number" | ||
] | ||
}, | ||
"twoDifferentWholeEnums": { | ||
"enum": [ | ||
"alpha", | ||
"beta", | ||
666, | ||
0, | ||
2, | ||
4, | ||
6 | ||
], | ||
"type": [ | ||
"string", | ||
"number" | ||
] | ||
}, | ||
"wholeEnum": { | ||
"enum": [ | ||
"alpha", | ||
"beta", | ||
666 | ||
], | ||
"type": [ | ||
"string", | ||
"number" | ||
] | ||
}, | ||
"wholeEnumWithLiteral": { | ||
"enum": [ | ||
"alpha", | ||
"beta", | ||
666, | ||
"bar" | ||
], | ||
"type": [ | ||
"string", | ||
"number" | ||
] | ||
}, | ||
"wholeEnumWithLiteralAndNull": { | ||
"enum": [ | ||
"alpha", | ||
"beta", | ||
666, | ||
"bar", | ||
null | ||
], | ||
"type": [ | ||
"string", | ||
"number", | ||
"null" | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"enumMembers", | ||
"enumMemberWithLiteral", | ||
"enumMemberWithLiteralAndNull", | ||
"enumMemberWithInterface", | ||
"enumMembersWithNumber", | ||
"wholeEnum", | ||
"wholeEnumWithLiteral", | ||
"wholeEnumWithLiteralAndNull", | ||
"twoDifferentEnumMembers", | ||
"twoDifferentWholeEnums" | ||
], | ||
"type": "object" | ||
} | ||
} | ||
} |
Oops, something went wrong.