diff --git a/tools/awslint/lib/rules/construct.ts b/tools/awslint/lib/rules/construct.ts index fbb624d3c2a97..d1b50276dde9c 100644 --- a/tools/awslint/lib/rules/construct.ts +++ b/tools/awslint/lib/rules/construct.ts @@ -80,7 +80,7 @@ export class ConstructReflection { } if (!found.isInterfaceType()) { - throw new Error(`Expecrting props struct ${this.propsFqn} to be an interface`); + throw new Error(`Expecting props struct ${this.propsFqn} to be an interface`); } return found; @@ -196,3 +196,19 @@ constructLinter.add({ e.assert(!e.ctx.sys.tryFindFqn(baseFqn), baseFqn); } }); + +constructLinter.add({ + code: 'props-no-unions', + message: 'props should not use TypeScript unions', + eval: e => { + if (!e.ctx.propsType) { return; } + if (!e.ctx.hasPropsArgument) { return; } + + // this rule only applies to L2 constructs + if (e.ctx.classType.name.startsWith('Cfn')) { return; } + + for (const property of e.ctx.propsType.ownProperties) { + e.assert(!property.type.unionOfTypes, `${e.ctx.propsFqn}.${property.name}`); + } + } +}); \ No newline at end of file