From 44a82fab355504d374be714454b1e5e0a2ff13f7 Mon Sep 17 00:00:00 2001 From: Blake Embrey Date: Tue, 18 Dec 2018 10:28:01 -0800 Subject: [PATCH 1/2] Check `modelDef.getType()` is defined before use --- packages/graphqlgen/src/generators/common.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/graphqlgen/src/generators/common.ts b/packages/graphqlgen/src/generators/common.ts index 8d3c0edc..4bcc377b 100644 --- a/packages/graphqlgen/src/generators/common.ts +++ b/packages/graphqlgen/src/generators/common.ts @@ -41,6 +41,7 @@ export function fieldsFromModelDefinition( // If model is of type `type TypeName = { ... }` if ( modelDef.kind === 'TypeAliasDefinition' && + (modelDef as TypeAliasDefinition).getType() && (modelDef as TypeAliasDefinition).getType().kind === 'AnonymousInterfaceAnnotation' ) { From b1515bcc8c20de3f04f8dbca9d98875f7044d7b3 Mon Sep 17 00:00:00 2001 From: Blake Embrey Date: Wed, 16 Jan 2019 11:02:04 -0800 Subject: [PATCH 2/2] Remove unnecessary type assertions --- packages/graphqlgen/src/generators/common.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/graphqlgen/src/generators/common.ts b/packages/graphqlgen/src/generators/common.ts index 4bcc377b..50d2ff26 100644 --- a/packages/graphqlgen/src/generators/common.ts +++ b/packages/graphqlgen/src/generators/common.ts @@ -41,11 +41,10 @@ export function fieldsFromModelDefinition( // If model is of type `type TypeName = { ... }` if ( modelDef.kind === 'TypeAliasDefinition' && - (modelDef as TypeAliasDefinition).getType() && - (modelDef as TypeAliasDefinition).getType().kind === - 'AnonymousInterfaceAnnotation' + modelDef.getType() && + modelDef.getType().kind === 'AnonymousInterfaceAnnotation' ) { - const interfaceDef = (modelDef as TypeAliasDefinition).getType() as AnonymousInterfaceAnnotation + const interfaceDef = modelDef.getType() as AnonymousInterfaceAnnotation return interfaceDef.fields }