我从typescript中的以下lambda函数开始:
export const handler: APIGatewayProxyHandler = async (event: APIGatewayProxyEvent, context: Context): Promise<APIGatewayProxyResult> => {
}在学习了typescript之后,我知道函数中的参数是给定的类型(分别是APIGatewayProxyEvent和Context )。类似地,函数的返回类型是通过在冒号(Promise<APIGatewayProxyResult>)后面添加它来定义的。
这里仍然使用了一种类型:handler: APIGatewayProxyHandler
这个类型意味着什么?它被称为什么?它肯定不是方法的返回类型,那么它是什么呢?
我搜索了各种类型的博客,仍然找不到任何关于这方面的信息。
谢谢!
发布于 2020-08-07 14:59:27
函数也可以有类型,例如:
type MyFunc = (a: number) => string;然后,当您创建一个函数时,您可以为其指定该类型:
const actualFunction: MyFunc = (a: number): string {
return 'hi';
}给常量一个类型会强制你的参数和返回类型与类型的签名相匹配,如果你不小心弄乱了返回类型,让APIGatewayProxyHandler出现会导致typescript报错。
https://stackoverflow.com/questions/63296666
复制相似问题