如何解决类型记录中的这些错误--我已经用cdk innit app --language typescript创建了这些错误。Vscode在配置中突出显示timeout和expires属性。
我在lib文件夹中的构造函数是
import * as cdk from "@aws-cdk/core";
import * as appsync from "@aws-cdk/aws-appsync";
import * as lambda from "@aws-cdk/aws-lambda";
export class Step03GraphQlStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const api = new appsync.GraphqlApi(this, "GRAPHQL_API", {
name: "cdk-api",
schema: appsync.Schema.fromAsset("graphql/schema.gql"),
authorizationConfig: {
defaultAuthorization: {
authorizationType: appsync.AuthorizationType.API_KEY,
apiKeyConfig: {
expires: cdk.Expiration.after(cdk.Duration.days(365)),
},
},
},
xrayEnabled: true,
});
new cdk.CfnOutput(this, "APIGraphQlURL", {
value: api.graphqlUrl,
});
new cdk.CfnOutput(this, "GraphQLAPIKey", {
value: api.apiKey || "",
});
const lambda_function = new lambda.Function(this, "LambdaFucntion", {
runtime: lambda.Runtime.NODEJS_12_X,
code: lambda.Code.fromAsset("lambda"),
handler: "index.handler", ///specfic fucntion in specific file
timeout: cdk.Duration.seconds(10),
});
const lambda_data_source = api.addLambdaDataSource(
"lamdaDataSource",
lambda_function
);
lambda_data_source.createResolver({
typeName: "Query",
fieldName: "notes",
});
lambda_data_source.createResolver({
typeName: "Query",
fieldName: "customNote",
});
}
}在运行tsc时,我会得到这些错误。
D:\Unicorn\cdk\step03_graphQl>tsc
lib/step03_graph_ql-stack.ts:17:13 - error TS2322: Type 'import("D:/Unicorn/cdk/step03_graphQl/node_modules/@aws-cdk/core/lib/expiration").Expiration' is not assignable to type 'import("D:/Unicorn/cdk/step03_graphQl/node_modules/@aws-cdk/aws-appsync/node_modules/@aws-cdk/core/lib/expiration").Expiration'.
Types of property 'isBefore' are incompatible.
Type '(t: import("D:/Unicorn/cdk/step03_graphQl/node_modules/@aws-cdk/core/lib/duration").Duration) => boolean' is not assignable to type '(t: import("D:/Unicorn/cdk/step03_graphQl/node_modules/@aws-cdk/aws-appsync/node_modules/@aws-cdk/core/lib/duration").Duration) => boolean'.
Types of parameters 't' and 't' are incompatible.
Type 'import("D:/Unicorn/cdk/step03_graphQl/node_modules/@aws-cdk/aws-appsync/node_modules/@aws-cdk/core/lib/duration").Duration' is not assignable to type 'import("D:/Unicorn/cdk/step03_graphQl/node_modules/@aws-cdk/core/lib/duration").Duration'.
Types have separate declarations of a private property 'amount'.
17 expires: cdk.Expiration.after(cdk.Duration.days(365)), ///set expiration for API Key
~~~~~~~
lib/step03_graph_ql-stack.ts:39:7 - error TS2741: Property 'minus' is missing in type 'import("D:/Unicorn/cdk/step03_graphQl/node_modules/@aws-cdk/core/lib/duration").Duration' but required in type 'import("D:/Unicorn/cdk/step03_graphQl/node_modules/@aws-cdk/aws-appsync/node_modules/@aws-cdk/core/lib/duration").Duration'.
39 timeout: cdk.Duration.seconds(10), ///Time for function to break. limit upto 15 mins
~~~~~~~
node_modules/@aws-cdk/aws-appsync/node_modules/@aws-cdk/core/lib/duration.d.ts:63:5
63 minus(rhs: Duration): Duration;
~~~~~
'minus' is declared here.
node_modules/@aws-cdk/aws-lambda/lib/function.d.ts:59:14
59 readonly timeout?: Duration;
~~~~~~~
The expected type comes from property 'timeout' which is declared here on type 'FunctionProps'
Found 2 errors.将包更新为相同版本的
"dependencies": {
"@aws-cdk/aws-appsync": "^1.121.0",
"@aws-cdk/aws-lambda": "^1.121.0",
"@aws-cdk/core": "1.121.0",
"source-map-support": "^0.5.16"
}发布于 2022-04-18 19:26:39
确保
在package.json
@aws-cdk/core、@aws-cdk/aws-appsync、@aws-cdk/aws-lambda与您的开发环境中的cdk具有相同的版本,与您在项目中定义的包相同或更高。(全局npm高于或等于您的项目)https://stackoverflow.com/questions/71915505
复制相似问题