Skip to content

Commit

Permalink
[typescript-fetch] Make instanceOf infer type and check for undefineds (
Browse files Browse the repository at this point in the history
  • Loading branch information
rickyrombo authored May 17, 2024
1 parent 2fe397c commit 62238c6
Show file tree
Hide file tree
Showing 149 changed files with 216 additions and 216 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import { {{modelName}}FromJSONTyped } from './{{modelName}}{{importFileExtension
/**
* Check if a given object implements the {{classname}} interface.
*/
export function instanceOf{{classname}}(value: object): boolean {
export function instanceOf{{classname}}(value: object): value is {{classname}} {
{{#vars}}
{{#required}}
if (!('{{name}}' in value)) return false;
if (!('{{name}}' in value) || value['{{name}}'] === undefined) return false;
{{/required}}
{{/vars}}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface Club {
/**
* Check if a given object implements the Club interface.
*/
export function instanceOfClub(value: object): boolean {
export function instanceOfClub(value: object): value is Club {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface Owner {
/**
* Check if a given object implements the Owner interface.
*/
export function instanceOfOwner(value: object): boolean {
export function instanceOfOwner(value: object): value is Owner {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface Club {
/**
* Check if a given object implements the Club interface.
*/
export function instanceOfClub(value: object): boolean {
export function instanceOfClub(value: object): value is Club {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface Owner {
/**
* Check if a given object implements the Owner interface.
*/
export function instanceOfOwner(value: object): boolean {
export function instanceOfOwner(value: object): value is Owner {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface AdditionalPropertiesClass {
/**
* Check if a given object implements the AdditionalPropertiesClass interface.
*/
export function instanceOfAdditionalPropertiesClass(value: object): boolean {
export function instanceOfAdditionalPropertiesClass(value: object): value is AdditionalPropertiesClass {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface AllOfWithSingleRef {
/**
* Check if a given object implements the AllOfWithSingleRef interface.
*/
export function instanceOfAllOfWithSingleRef(value: object): boolean {
export function instanceOfAllOfWithSingleRef(value: object): value is AllOfWithSingleRef {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export interface Animal {
/**
* Check if a given object implements the Animal interface.
*/
export function instanceOfAnimal(value: object): boolean {
if (!('className' in value)) return false;
export function instanceOfAnimal(value: object): value is Animal {
if (!('className' in value) || value['className'] === undefined) return false;
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface ArrayOfArrayOfNumberOnly {
/**
* Check if a given object implements the ArrayOfArrayOfNumberOnly interface.
*/
export function instanceOfArrayOfArrayOfNumberOnly(value: object): boolean {
export function instanceOfArrayOfArrayOfNumberOnly(value: object): value is ArrayOfArrayOfNumberOnly {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface ArrayOfNumberOnly {
/**
* Check if a given object implements the ArrayOfNumberOnly interface.
*/
export function instanceOfArrayOfNumberOnly(value: object): boolean {
export function instanceOfArrayOfNumberOnly(value: object): value is ArrayOfNumberOnly {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface ArrayTest {
/**
* Check if a given object implements the ArrayTest interface.
*/
export function instanceOfArrayTest(value: object): boolean {
export function instanceOfArrayTest(value: object): value is ArrayTest {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface Capitalization {
/**
* Check if a given object implements the Capitalization interface.
*/
export function instanceOfCapitalization(value: object): boolean {
export function instanceOfCapitalization(value: object): value is Capitalization {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface Cat extends Animal {
/**
* Check if a given object implements the Cat interface.
*/
export function instanceOfCat(value: object): boolean {
export function instanceOfCat(value: object): value is Cat {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export interface Category {
/**
* Check if a given object implements the Category interface.
*/
export function instanceOfCategory(value: object): boolean {
if (!('name' in value)) return false;
export function instanceOfCategory(value: object): value is Category {
if (!('name' in value) || value['name'] === undefined) return false;
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface ChildWithNullable extends ParentWithNullable {
/**
* Check if a given object implements the ChildWithNullable interface.
*/
export function instanceOfChildWithNullable(value: object): boolean {
export function instanceOfChildWithNullable(value: object): value is ChildWithNullable {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface ClassModel {
/**
* Check if a given object implements the ClassModel interface.
*/
export function instanceOfClassModel(value: object): boolean {
export function instanceOfClassModel(value: object): value is ClassModel {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface Client {
/**
* Check if a given object implements the Client interface.
*/
export function instanceOfClient(value: object): boolean {
export function instanceOfClient(value: object): value is Client {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface DeprecatedObject {
/**
* Check if a given object implements the DeprecatedObject interface.
*/
export function instanceOfDeprecatedObject(value: object): boolean {
export function instanceOfDeprecatedObject(value: object): value is DeprecatedObject {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface Dog extends Animal {
/**
* Check if a given object implements the Dog interface.
*/
export function instanceOfDog(value: object): boolean {
export function instanceOfDog(value: object): value is Dog {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export type EnumArraysArrayEnumEnum = typeof EnumArraysArrayEnumEnum[keyof typeo
/**
* Check if a given object implements the EnumArrays interface.
*/
export function instanceOfEnumArrays(value: object): boolean {
export function instanceOfEnumArrays(value: object): value is EnumArrays {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ export type EnumTestEnumNumberEnum = typeof EnumTestEnumNumberEnum[keyof typeof
/**
* Check if a given object implements the EnumTest interface.
*/
export function instanceOfEnumTest(value: object): boolean {
if (!('enumStringRequired' in value)) return false;
export function instanceOfEnumTest(value: object): value is EnumTest {
if (!('enumStringRequired' in value) || value['enumStringRequired'] === undefined) return false;
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface FakeBigDecimalMap200Response {
/**
* Check if a given object implements the FakeBigDecimalMap200Response interface.
*/
export function instanceOfFakeBigDecimalMap200Response(value: object): boolean {
export function instanceOfFakeBigDecimalMap200Response(value: object): value is FakeBigDecimalMap200Response {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface FileSchemaTestClass {
/**
* Check if a given object implements the FileSchemaTestClass interface.
*/
export function instanceOfFileSchemaTestClass(value: object): boolean {
export function instanceOfFileSchemaTestClass(value: object): value is FileSchemaTestClass {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface Foo {
/**
* Check if a given object implements the Foo interface.
*/
export function instanceOfFoo(value: object): boolean {
export function instanceOfFoo(value: object): value is Foo {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface FooGetDefaultResponse {
/**
* Check if a given object implements the FooGetDefaultResponse interface.
*/
export function instanceOfFooGetDefaultResponse(value: object): boolean {
export function instanceOfFooGetDefaultResponse(value: object): value is FooGetDefaultResponse {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ export interface FormatTest {
/**
* Check if a given object implements the FormatTest interface.
*/
export function instanceOfFormatTest(value: object): boolean {
if (!('number' in value)) return false;
if (!('_byte' in value)) return false;
if (!('date' in value)) return false;
if (!('password' in value)) return false;
export function instanceOfFormatTest(value: object): value is FormatTest {
if (!('number' in value) || value['number'] === undefined) return false;
if (!('_byte' in value) || value['_byte'] === undefined) return false;
if (!('date' in value) || value['date'] === undefined) return false;
if (!('password' in value) || value['password'] === undefined) return false;
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface HasOnlyReadOnly {
/**
* Check if a given object implements the HasOnlyReadOnly interface.
*/
export function instanceOfHasOnlyReadOnly(value: object): boolean {
export function instanceOfHasOnlyReadOnly(value: object): value is HasOnlyReadOnly {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface HealthCheckResult {
/**
* Check if a given object implements the HealthCheckResult interface.
*/
export function instanceOfHealthCheckResult(value: object): boolean {
export function instanceOfHealthCheckResult(value: object): value is HealthCheckResult {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface List {
/**
* Check if a given object implements the List interface.
*/
export function instanceOfList(value: object): boolean {
export function instanceOfList(value: object): value is List {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export type MapTestMapOfEnumStringEnum = typeof MapTestMapOfEnumStringEnum[keyof
/**
* Check if a given object implements the MapTest interface.
*/
export function instanceOfMapTest(value: object): boolean {
export function instanceOfMapTest(value: object): value is MapTest {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface MixedPropertiesAndAdditionalPropertiesClass {
/**
* Check if a given object implements the MixedPropertiesAndAdditionalPropertiesClass interface.
*/
export function instanceOfMixedPropertiesAndAdditionalPropertiesClass(value: object): boolean {
export function instanceOfMixedPropertiesAndAdditionalPropertiesClass(value: object): value is MixedPropertiesAndAdditionalPropertiesClass {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface Model200Response {
/**
* Check if a given object implements the Model200Response interface.
*/
export function instanceOfModel200Response(value: object): boolean {
export function instanceOfModel200Response(value: object): value is Model200Response {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface ModelApiResponse {
/**
* Check if a given object implements the ModelApiResponse interface.
*/
export function instanceOfModelApiResponse(value: object): boolean {
export function instanceOfModelApiResponse(value: object): value is ModelApiResponse {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface ModelFile {
/**
* Check if a given object implements the ModelFile interface.
*/
export function instanceOfModelFile(value: object): boolean {
export function instanceOfModelFile(value: object): value is ModelFile {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export interface Name {
/**
* Check if a given object implements the Name interface.
*/
export function instanceOfName(value: object): boolean {
if (!('name' in value)) return false;
export function instanceOfName(value: object): value is Name {
if (!('name' in value) || value['name'] === undefined) return false;
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export interface NullableClass {
/**
* Check if a given object implements the NullableClass interface.
*/
export function instanceOfNullableClass(value: object): boolean {
export function instanceOfNullableClass(value: object): value is NullableClass {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface NumberOnly {
/**
* Check if a given object implements the NumberOnly interface.
*/
export function instanceOfNumberOnly(value: object): boolean {
export function instanceOfNumberOnly(value: object): value is NumberOnly {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export interface ObjectWithDeprecatedFields {
/**
* Check if a given object implements the ObjectWithDeprecatedFields interface.
*/
export function instanceOfObjectWithDeprecatedFields(value: object): boolean {
export function instanceOfObjectWithDeprecatedFields(value: object): value is ObjectWithDeprecatedFields {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export type OrderStatusEnum = typeof OrderStatusEnum[keyof typeof OrderStatusEnu
/**
* Check if a given object implements the Order interface.
*/
export function instanceOfOrder(value: object): boolean {
export function instanceOfOrder(value: object): value is Order {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface OuterComposite {
/**
* Check if a given object implements the OuterComposite interface.
*/
export function instanceOfOuterComposite(value: object): boolean {
export function instanceOfOuterComposite(value: object): value is OuterComposite {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export interface OuterObjectWithEnumProperty {
/**
* Check if a given object implements the OuterObjectWithEnumProperty interface.
*/
export function instanceOfOuterObjectWithEnumProperty(value: object): boolean {
if (!('value' in value)) return false;
export function instanceOfOuterObjectWithEnumProperty(value: object): value is OuterObjectWithEnumProperty {
if (!('value' in value) || value['value'] === undefined) return false;
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export type ParentWithNullableTypeEnum = typeof ParentWithNullableTypeEnum[keyof
/**
* Check if a given object implements the ParentWithNullable interface.
*/
export function instanceOfParentWithNullable(value: object): boolean {
export function instanceOfParentWithNullable(value: object): value is ParentWithNullable {
return true;
}

Expand Down
Loading

0 comments on commit 62238c6

Please sign in to comment.