Skip to content

Commit

Permalink
fix(model-visitor.ts): support for when strict option is on
Browse files Browse the repository at this point in the history
fix #10 #11
  • Loading branch information
nartc committed Feb 5, 2020
1 parent 11e4abb commit 6fb95ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export function isPrimitiveType(type: tss.Type): boolean {
);
}

export function isNullableUnionType(type: tss.Type): boolean {
return type.isUnion() && (type as any)?.isNullableType();
}

export function isAnyType(
type: tss.Type,
typeChecker: tss.TypeChecker,
Expand Down
7 changes: 6 additions & 1 deletion src/model-visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
hasPropertyKey,
isAnyType,
isArrayType,
isNullableUnionType,
isPrimitiveType,
isTypeLiteral,
} from './ast-utils';
Expand Down Expand Up @@ -165,11 +166,15 @@ export class ModelVisitor {
return undefined;
}

const type = typeChecker.getTypeAtLocation(node);
let type = typeChecker.getTypeAtLocation(node);
if (!type) {
return undefined;
}

if (isNullableUnionType(type)) {
type = type.getNonNullableType();
}

if (
isPrimitiveType(type) ||
isTypeLiteral(type) ||
Expand Down

0 comments on commit 6fb95ee

Please sign in to comment.