'Using CDKv2 with TypeSCript giving error ts2345
I am trying to learn TypeScript and CDKV2.
test.ts
import 'source-map-support/register';
import * as cdk from 'aws-cdk-lib';
import { teststack } from '../src/teststack';
const queueName = 'input-queue';
const app = new cdk.App();
new Task2Stack(app, 'teststack', { queueName: queueName });
teststack.ts
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as sqs from 'aws-cdk-lib/aws-sqs';
export interface getStackProps extends cdk.StackProps {
readonly queueName: string;
env: {
account: '123456789012',
region: 'us-east-1'
}
}
export class teststack extends cdk.Stack {
constructor(scope: Construct, id: string, props: getStackProps) {
super(scope, id, props);
// The code that defines your stack goes here
// example resource
const queue = new sqs.Queue(this, '.....', {
visibilityTimeout: cdk.Duration.seconds(300),
queueName: props.queueName,
});
}
}
Error:
Argument of type '{ queueName: string; }' is not assignable to parameter of type 'getStackProps'.
Property 'env' is missing in type '{ queueName: string; }' but required in type 'getStackProps'.ts(2345)
teststack.ts(7, 3): 'env' is declared here.
Question: If I remove/comment env it works fine. Is it possible to convert getStackProps to a function so that I can eliminate this error ? What is causing this error ? Can anyone please explain ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
