我已经升级到无服务器3,运行类型记录。之后,在无服务器配置文件中出现类型匹配错误。
部分我的serverless.ts文件是
const serverlessConfiguration: Serverless = {
service: 'hello',
frameworkVersion: '3',
useDotenv: true,
plugins: ['serverless-webpack', 'serverless-domain-manager', 'serverless-iam-roles-per-function', 'serverless-certificate-creator'],
provider: {
name: 'aws',
runtime: 'nodejs14.x',
region: 'ap-southeast-2',
apiGateway: {
minimumCompressionSize: 1024,
shouldStartNameWithService: true,
},
environment: {
AWS_NODEJS_CONNECTION_REUSE_ENABLED: '1',
},
},
functions: {hello},
custom: {hello/index.ts文件的架构有问题
import schema from './schema';
import { handlerPath } from '@libs/handlerResolver';
export default {
handler: `${handlerPath(__dirname)}/handler.main`,
events: [
{
http: {
method: 'post',
path: 'hello',
private: false,
request: {
schemas: {
'application/json': schema
}
}
}
}
]}
我读到http.request.schema已经被http.request.schemas取代了
我得到的错误信息是
Type '{ schemas: { 'application/json': { readonly type: "object"; readonly properties: { readonly name: { readonly type: "string"; }; }; readonly required: readonly ["name"]; }; }; }' has no properties in common with type 'HttpRequestValidation'.发布于 2022-02-17 20:18:09
包@type/serverless有错误的规范
移除此包
npm remove @types/serverless 添加无服务器的类型记录包
npm i -D @serverless/typescript将serverless.ts中的导入更改为
import type {Serverless} from 'serverless/aws';至
import type {AWS} from "@serverless/typescript";确保index.ts有计划,而不是模式。
最后的index.ts文件如下所示
https://stackoverflow.com/questions/71164380
复制相似问题