diff --git a/tools/awslint/lib/rules/construct.ts b/tools/awslint/lib/rules/construct.ts index 500705432c1de..f594e39d9a961 100644 --- a/tools/awslint/lib/rules/construct.ts +++ b/tools/awslint/lib/rules/construct.ts @@ -79,7 +79,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; @@ -193,4 +193,20 @@ constructLinter.add({ const baseFqn = `${e.ctx.classType.fqn}Base`; e.assert(!e.ctx.sys.tryFindFqn(baseFqn), baseFqn); } -}); \ No newline at end of file +}); + +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}`); + } + } +});