-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Block usage of enum types but allow them as relaxed types (#17)
- Loading branch information
1 parent
32e3352
commit 7fa60b3
Showing
12 changed files
with
704 additions
and
29 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
12 changes: 12 additions & 0 deletions
12
ndc-lambda-sdk/test/inference/relaxed-types/enum-types-invalid.ts
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,12 @@ | ||
type StringLiteralEnum = "1st" | "2nd" | Promise<"3rd"> | ||
|
||
/** | ||
* @readonly | ||
* @allowrelaxedtypes | ||
*/ | ||
export function enumTypesFunction( | ||
stringLiteralEnum: StringLiteralEnum, | ||
inlineStringLiteralEnum: "1st" | "2nd" | void, | ||
): string { | ||
return "" | ||
} |
70 changes: 70 additions & 0 deletions
70
ndc-lambda-sdk/test/inference/relaxed-types/enum-types-valid.ts
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,70 @@ | ||
enum StringEnum { | ||
First = "First", | ||
Second = "Second" | ||
} | ||
|
||
enum NumberEnum { | ||
First = 1, | ||
Second = 2 | ||
} | ||
|
||
enum MixedEnum { | ||
Dog = "Dog", | ||
Cat = "Cat", | ||
Other = 1234, | ||
} | ||
|
||
const enum ConstEnum { | ||
First = "first", | ||
Second = "second", | ||
} | ||
|
||
enum ComputedEnum { | ||
Gross = "Gross".length, | ||
Foul = "Foul".length | ||
} | ||
|
||
enum ComputedSingleItemEnum { | ||
Single = "Single".length | ||
} | ||
|
||
type StringLiteralEnum = "1st" | "2nd" | ||
|
||
type NumberLiteralEnum = 0 | 1 | 2 | ||
|
||
type MixedLiteralEnum = true | false | 0 | 1 | "1st" | "2nd" | ||
|
||
const ConstObjEnumVal = { | ||
Plant: "plant", | ||
Animal: "animal" | ||
} as const; | ||
|
||
type ConstObjEnum = typeof ConstObjEnumVal[keyof typeof ConstObjEnumVal] | ||
|
||
/** | ||
* @readonly | ||
* @allowrelaxedtypes | ||
*/ | ||
export function enumTypesFunction( | ||
stringEnum: StringEnum, | ||
numberEnum: NumberEnum, | ||
mixedEnum: MixedEnum, | ||
constEnum: ConstEnum, | ||
computedEnum: ComputedEnum, | ||
computedSingleItemEnum: ComputedSingleItemEnum, | ||
stringLiteralEnum: StringLiteralEnum, | ||
stringLiteralEnumMaybe: StringLiteralEnum | undefined, | ||
inlineStringLiteralEnum: "1st" | "2nd", | ||
inlineStringLiteralEnumMaybe: "1st" | "2nd" | null, | ||
numberLiteralEnum: NumberLiteralEnum, | ||
numberLiteralEnumMaybe: NumberLiteralEnum | null, | ||
inlineNumberLiteralEnum: 0 | 1 | 2, | ||
inlineNumberLiteralEnumMaybe: 0 | 1 | 2 | undefined, | ||
mixedLiteralEnum: MixedLiteralEnum, | ||
mixedLiteralEnumMaybe: MixedLiteralEnum | undefined | null, | ||
inlineMixedLiteralEnum: true | 1 | "first", | ||
inlineMixedLiteralEnumMaybe: true | 1 | "first" | undefined | null, | ||
constObjEnum: ConstObjEnum, | ||
): string { | ||
return "" | ||
} |
Oops, something went wrong.