Skip to content

Commit 62238c6

Browse files
authored
[typescript-fetch] Make instanceOf infer type and check for undefineds (OpenAPITools#18694)
1 parent 2fe397c commit 62238c6

File tree

149 files changed

+216
-216
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+216
-216
lines changed

modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import { {{modelName}}FromJSONTyped } from './{{modelName}}{{importFileExtension
2020
/**
2121
* Check if a given object implements the {{classname}} interface.
2222
*/
23-
export function instanceOf{{classname}}(value: object): boolean {
23+
export function instanceOf{{classname}}(value: object): value is {{classname}} {
2424
{{#vars}}
2525
{{#required}}
26-
if (!('{{name}}' in value)) return false;
26+
if (!('{{name}}' in value) || value['{{name}}'] === undefined) return false;
2727
{{/required}}
2828
{{/vars}}
2929
return true;

samples/client/petstore/typescript-fetch/builds/allOf-nullable/models/Club.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export interface Club {
3737
/**
3838
* Check if a given object implements the Club interface.
3939
*/
40-
export function instanceOfClub(value: object): boolean {
40+
export function instanceOfClub(value: object): value is Club {
4141
return true;
4242
}
4343

samples/client/petstore/typescript-fetch/builds/allOf-nullable/models/Owner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export interface Owner {
3030
/**
3131
* Check if a given object implements the Owner interface.
3232
*/
33-
export function instanceOfOwner(value: object): boolean {
33+
export function instanceOfOwner(value: object): value is Owner {
3434
return true;
3535
}
3636

samples/client/petstore/typescript-fetch/builds/allOf-readonly/models/Club.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export interface Club {
3737
/**
3838
* Check if a given object implements the Club interface.
3939
*/
40-
export function instanceOfClub(value: object): boolean {
40+
export function instanceOfClub(value: object): value is Club {
4141
return true;
4242
}
4343

samples/client/petstore/typescript-fetch/builds/allOf-readonly/models/Owner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export interface Owner {
3030
/**
3131
* Check if a given object implements the Owner interface.
3232
*/
33-
export function instanceOfOwner(value: object): boolean {
33+
export function instanceOfOwner(value: object): value is Owner {
3434
return true;
3535
}
3636

samples/client/petstore/typescript-fetch/builds/default-v3.0/models/AdditionalPropertiesClass.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export interface AdditionalPropertiesClass {
3636
/**
3737
* Check if a given object implements the AdditionalPropertiesClass interface.
3838
*/
39-
export function instanceOfAdditionalPropertiesClass(value: object): boolean {
39+
export function instanceOfAdditionalPropertiesClass(value: object): value is AdditionalPropertiesClass {
4040
return true;
4141
}
4242

samples/client/petstore/typescript-fetch/builds/default-v3.0/models/AllOfWithSingleRef.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export interface AllOfWithSingleRef {
4343
/**
4444
* Check if a given object implements the AllOfWithSingleRef interface.
4545
*/
46-
export function instanceOfAllOfWithSingleRef(value: object): boolean {
46+
export function instanceOfAllOfWithSingleRef(value: object): value is AllOfWithSingleRef {
4747
return true;
4848
}
4949

samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Animal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export interface Animal {
3838
/**
3939
* Check if a given object implements the Animal interface.
4040
*/
41-
export function instanceOfAnimal(value: object): boolean {
42-
if (!('className' in value)) return false;
41+
export function instanceOfAnimal(value: object): value is Animal {
42+
if (!('className' in value) || value['className'] === undefined) return false;
4343
return true;
4444
}
4545

samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ArrayOfArrayOfNumberOnly.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export interface ArrayOfArrayOfNumberOnly {
3030
/**
3131
* Check if a given object implements the ArrayOfArrayOfNumberOnly interface.
3232
*/
33-
export function instanceOfArrayOfArrayOfNumberOnly(value: object): boolean {
33+
export function instanceOfArrayOfArrayOfNumberOnly(value: object): value is ArrayOfArrayOfNumberOnly {
3434
return true;
3535
}
3636

samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ArrayOfNumberOnly.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export interface ArrayOfNumberOnly {
3030
/**
3131
* Check if a given object implements the ArrayOfNumberOnly interface.
3232
*/
33-
export function instanceOfArrayOfNumberOnly(value: object): boolean {
33+
export function instanceOfArrayOfNumberOnly(value: object): value is ArrayOfNumberOnly {
3434
return true;
3535
}
3636

0 commit comments

Comments
 (0)