Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const union = this.renderTypeUnion(resourceContext, itemTypes);
if (schema.isMapProperty(propSpec)) {
alternatives.push(`{ [key: string]: (${union}) }`);
} else {
// To make TSLint happy, we have to either emit: SingleType[] or Array
if (union.indexOf('|') !== -1) {
alternatives.push(`Array<${union}>`);
} else {
alternatives.push(`${union}[]`);
}
}
}
// Yes, some types can be both collection and scalar. Looking at you, SAM.
if (schema.isScalarPropery(propSpec)) {
// Scalar type
const typeNames = scalarTypeNames(propSpec);
const types = genspec.specTypesToCodeTypes(resourceContext, typeNames);
alternatives.push(this.renderTypeUnion(resourceContext, types));
}
// Only if this property is not of a "tokenizable type" (string, string[],
// number in the future) we add a type union for `cdk.Token`. We rather
// everything to be tokenizable because there are languages that do not
// support union types (i.e. Java, .NET), so we lose type safety if we have
// a union.
if (!tokenizableType(alternatives) && propName !== 'Tags') {
alternatives.push(genspec.TOKEN_NAME.fqn);
}
return alternatives.join(' | ');
}