export interface AWSTags {
CreatedBy: string;
Environment: EnvironmentMap;
Name: string;
OwnedBy: string;
Platform: string;
Product: string;
Runbook: string;
Service: string;
}
Another script contains the following function to generate an object that adheres to the specified interface.
export const getAWSTags = (stackName: string, environment: EnvironmentMap, createdBy: string): AWSTags => ({
CreatedBy: createdBy,
Environment: environment,
Name: stackName,
OwnedBy: "owner",
Platform: "platform",
Product: "product",
Runbook: "url",
Service: `${stackName}-service`,
});
Just for clarity, EnvironmentMap is a data type that can return one of three strings.
When attempting to assign the result of this function to AWS tags, which requires the structure shown below, error code 2322 is encountered.
readonly tags?: {
[key: string]: string;
};
const app = new App();
const stack = new Stack(app, stackName, {
env: {
account: AWS.ACCOUNT,
region: AWS.REGION,
},
tags: getAWSTags(stackName, environment, 'creator'),
});
Type 'AWSTags' is not assignable to type '{ [key: string]: string; }'. Index signature for type 'string' is missing in type 'AWSTags'.ts(2322)
Are there different methods or alternatives available to resolve this issue?
UPDATE: The error seems to be resolved by modifying the interface as follows.
export interface AWSTags {
[key: string]: string;
CreatedBy: string;
Environment: EnvironmentMap;
Name: string;
OwnedBy: string;
Platform: string;
Product: string;
Runbook: string;
Service: string;
}
Thank you