Skip to content

Commit

Permalink
Fix casts for typescript-fetch enum keys not working on number-based …
Browse files Browse the repository at this point in the history
…enums (OpenAPITools#19075)

Co-authored-by: Cornelissen, Cas <cas.cornelissen@wartsila.com>
  • Loading branch information
cascornelissen and Cornelissen, Cas authored Jul 4, 2024
1 parent 21ad242 commit add5c2e
Show file tree
Hide file tree
Showing 22 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
export function instanceOf{{classname}}(value: any): boolean {
for (const key in {{classname}}) {
if (Object.prototype.hasOwnProperty.call({{classname}}, key)) {
if (({{classname}} as Record<string, {{classname}}>)[key] === value) {
if ({{classname}}[key as keyof typeof {{classname}}] === value) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type EnumClass = typeof EnumClass[keyof typeof EnumClass];
export function instanceOfEnumClass(value: any): boolean {
for (const key in EnumClass) {
if (Object.prototype.hasOwnProperty.call(EnumClass, key)) {
if ((EnumClass as Record<string, EnumClass>)[key] === value) {
if (EnumClass[key as keyof typeof EnumClass] === value) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type OuterEnum = typeof OuterEnum[keyof typeof OuterEnum];
export function instanceOfOuterEnum(value: any): boolean {
for (const key in OuterEnum) {
if (Object.prototype.hasOwnProperty.call(OuterEnum, key)) {
if ((OuterEnum as Record<string, OuterEnum>)[key] === value) {
if (OuterEnum[key as keyof typeof OuterEnum] === value) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type OuterEnumDefaultValue = typeof OuterEnumDefaultValue[keyof typeof Ou
export function instanceOfOuterEnumDefaultValue(value: any): boolean {
for (const key in OuterEnumDefaultValue) {
if (Object.prototype.hasOwnProperty.call(OuterEnumDefaultValue, key)) {
if ((OuterEnumDefaultValue as Record<string, OuterEnumDefaultValue>)[key] === value) {
if (OuterEnumDefaultValue[key as keyof typeof OuterEnumDefaultValue] === value) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type OuterEnumInteger = typeof OuterEnumInteger[keyof typeof OuterEnumInt
export function instanceOfOuterEnumInteger(value: any): boolean {
for (const key in OuterEnumInteger) {
if (Object.prototype.hasOwnProperty.call(OuterEnumInteger, key)) {
if ((OuterEnumInteger as Record<string, OuterEnumInteger>)[key] === value) {
if (OuterEnumInteger[key as keyof typeof OuterEnumInteger] === value) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type OuterEnumIntegerDefaultValue = typeof OuterEnumIntegerDefaultValue[k
export function instanceOfOuterEnumIntegerDefaultValue(value: any): boolean {
for (const key in OuterEnumIntegerDefaultValue) {
if (Object.prototype.hasOwnProperty.call(OuterEnumIntegerDefaultValue, key)) {
if ((OuterEnumIntegerDefaultValue as Record<string, OuterEnumIntegerDefaultValue>)[key] === value) {
if (OuterEnumIntegerDefaultValue[key as keyof typeof OuterEnumIntegerDefaultValue] === value) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type SingleRefType = typeof SingleRefType[keyof typeof SingleRefType];
export function instanceOfSingleRefType(value: any): boolean {
for (const key in SingleRefType) {
if (Object.prototype.hasOwnProperty.call(SingleRefType, key)) {
if ((SingleRefType as Record<string, SingleRefType>)[key] === value) {
if (SingleRefType[key as keyof typeof SingleRefType] === value) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type NumberEnum = typeof NumberEnum[keyof typeof NumberEnum];
export function instanceOfNumberEnum(value: any): boolean {
for (const key in NumberEnum) {
if (Object.prototype.hasOwnProperty.call(NumberEnum, key)) {
if ((NumberEnum as Record<string, NumberEnum>)[key] === value) {
if (NumberEnum[key as keyof typeof NumberEnum] === value) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type StringEnum = typeof StringEnum[keyof typeof StringEnum];
export function instanceOfStringEnum(value: any): boolean {
for (const key in StringEnum) {
if (Object.prototype.hasOwnProperty.call(StringEnum, key)) {
if ((StringEnum as Record<string, StringEnum>)[key] === value) {
if (StringEnum[key as keyof typeof StringEnum] === value) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type BehaviorType = typeof BehaviorType[keyof typeof BehaviorType];
export function instanceOfBehaviorType(value: any): boolean {
for (const key in BehaviorType) {
if (Object.prototype.hasOwnProperty.call(BehaviorType, key)) {
if ((BehaviorType as Record<string, BehaviorType>)[key] === value) {
if (BehaviorType[key as keyof typeof BehaviorType] === value) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type DeploymentRequestStatus = typeof DeploymentRequestStatus[keyof typeo
export function instanceOfDeploymentRequestStatus(value: any): boolean {
for (const key in DeploymentRequestStatus) {
if (Object.prototype.hasOwnProperty.call(DeploymentRequestStatus, key)) {
if ((DeploymentRequestStatus as Record<string, DeploymentRequestStatus>)[key] === value) {
if (DeploymentRequestStatus[key as keyof typeof DeploymentRequestStatus] === value) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export type ErrorCode = typeof ErrorCode[keyof typeof ErrorCode];
export function instanceOfErrorCode(value: any): boolean {
for (const key in ErrorCode) {
if (Object.prototype.hasOwnProperty.call(ErrorCode, key)) {
if ((ErrorCode as Record<string, ErrorCode>)[key] === value) {
if (ErrorCode[key as keyof typeof ErrorCode] === value) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type PetPartType = typeof PetPartType[keyof typeof PetPartType];
export function instanceOfPetPartType(value: any): boolean {
for (const key in PetPartType) {
if (Object.prototype.hasOwnProperty.call(PetPartType, key)) {
if ((PetPartType as Record<string, PetPartType>)[key] === value) {
if (PetPartType[key as keyof typeof PetPartType] === value) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type WarningCode = typeof WarningCode[keyof typeof WarningCode];
export function instanceOfWarningCode(value: any): boolean {
for (const key in WarningCode) {
if (Object.prototype.hasOwnProperty.call(WarningCode, key)) {
if ((WarningCode as Record<string, WarningCode>)[key] === value) {
if (WarningCode[key as keyof typeof WarningCode] === value) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type EnumClass = typeof EnumClass[keyof typeof EnumClass];
export function instanceOfEnumClass(value: any): boolean {
for (const key in EnumClass) {
if (Object.prototype.hasOwnProperty.call(EnumClass, key)) {
if ((EnumClass as Record<string, EnumClass>)[key] === value) {
if (EnumClass[key as keyof typeof EnumClass] === value) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type OuterEnum = typeof OuterEnum[keyof typeof OuterEnum];
export function instanceOfOuterEnum(value: any): boolean {
for (const key in OuterEnum) {
if (Object.prototype.hasOwnProperty.call(OuterEnum, key)) {
if ((OuterEnum as Record<string, OuterEnum>)[key] === value) {
if (OuterEnum[key as keyof typeof OuterEnum] === value) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type OuterEnumDefaultValue = typeof OuterEnumDefaultValue[keyof typeof Ou
export function instanceOfOuterEnumDefaultValue(value: any): boolean {
for (const key in OuterEnumDefaultValue) {
if (Object.prototype.hasOwnProperty.call(OuterEnumDefaultValue, key)) {
if ((OuterEnumDefaultValue as Record<string, OuterEnumDefaultValue>)[key] === value) {
if (OuterEnumDefaultValue[key as keyof typeof OuterEnumDefaultValue] === value) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type OuterEnumInteger = typeof OuterEnumInteger[keyof typeof OuterEnumInt
export function instanceOfOuterEnumInteger(value: any): boolean {
for (const key in OuterEnumInteger) {
if (Object.prototype.hasOwnProperty.call(OuterEnumInteger, key)) {
if ((OuterEnumInteger as Record<string, OuterEnumInteger>)[key] === value) {
if (OuterEnumInteger[key as keyof typeof OuterEnumInteger] === value) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type OuterEnumIntegerDefaultValue = typeof OuterEnumIntegerDefaultValue[k
export function instanceOfOuterEnumIntegerDefaultValue(value: any): boolean {
for (const key in OuterEnumIntegerDefaultValue) {
if (Object.prototype.hasOwnProperty.call(OuterEnumIntegerDefaultValue, key)) {
if ((OuterEnumIntegerDefaultValue as Record<string, OuterEnumIntegerDefaultValue>)[key] === value) {
if (OuterEnumIntegerDefaultValue[key as keyof typeof OuterEnumIntegerDefaultValue] === value) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type SingleRefType = typeof SingleRefType[keyof typeof SingleRefType];
export function instanceOfSingleRefType(value: any): boolean {
for (const key in SingleRefType) {
if (Object.prototype.hasOwnProperty.call(SingleRefType, key)) {
if ((SingleRefType as Record<string, SingleRefType>)[key] === value) {
if (SingleRefType[key as keyof typeof SingleRefType] === value) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export enum NumberEnum {
export function instanceOfNumberEnum(value: any): boolean {
for (const key in NumberEnum) {
if (Object.prototype.hasOwnProperty.call(NumberEnum, key)) {
if ((NumberEnum as Record<string, NumberEnum>)[key] === value) {
if (NumberEnum[key as keyof typeof NumberEnum] === value) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export enum StringEnum {
export function instanceOfStringEnum(value: any): boolean {
for (const key in StringEnum) {
if (Object.prototype.hasOwnProperty.call(StringEnum, key)) {
if ((StringEnum as Record<string, StringEnum>)[key] === value) {
if (StringEnum[key as keyof typeof StringEnum] === value) {
return true;
}
}
Expand Down

0 comments on commit add5c2e

Please sign in to comment.