Skip to content

Commit

Permalink
fix(plugin): recognize boolean properties in strict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Jun 23, 2020
1 parent 6e4a962 commit 24dbec5
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/plugin/utils/plugin-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function getDecoratorOrUndefinedByNames(
names: string[],
decorators: ts.NodeArray<ts.Decorator>,
): ts.Decorator | undefined {
return (decorators || ts.createNodeArray()).find(item =>
return (decorators || ts.createNodeArray()).find((item) =>
names.includes(getDecoratorName(item)),
);
}
Expand Down Expand Up @@ -62,6 +62,9 @@ export function getTypeReferenceAsString(
if (text === Date.name) {
return text;
}
if (isOptionalBoolean(text)) {
return Boolean.name;
}
if (isEnum(type)) {
return getText(type, typeChecker);
}
Expand Down Expand Up @@ -109,8 +112,8 @@ export function hasPropertyKey(
properties: ts.NodeArray<ts.PropertyAssignment>,
): boolean {
return properties
.filter(item => !isDynamicallyAdded(item))
.some(item => item.name.getText() === key);
.filter((item) => !isDynamicallyAdded(item))
.some((item) => item.name.getText() === key);
}

export function replaceImportPath(typeReference: string, fileName: string) {
Expand Down Expand Up @@ -246,3 +249,11 @@ export function extractTypeArgumentIfArray(type: ts.Type) {
isArray: false,
};
}

/**
* when "strict" mode enabled, TypeScript transform optional boolean properties to "boolean | undefined"
* @param text
*/
function isOptionalBoolean(text: string) {
return typeof text === 'string' && text === 'boolean | undefined';
}

0 comments on commit 24dbec5

Please sign in to comment.