TypeScript版本: 3.8.0-dev.20191122
源代码:
interface PromiseAction extends Promise<Action> {}
type Action = {type: string} | PromiseAction;
const createFooAction = async (): Promise<Action> => {type: "foo"};
- tsconfig.json
{
"compilerOptions": {
"target": "es2017",
"allowSyntheticDefaultImports": true,
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"strictNullChecks": true,
},
"include": ["src/**/*"]
}
预期行为:
成功进行类型检查或抛出一些错误
实际行为:
tsc崩溃,报错信息为RangeError: Maximum call stack size exceeded
$ npm run check
> @ check /Users/okamoto-k/sandbox
> tsc --noEmit
/Users/okamoto-k/sandbox/node_modules/typescript/lib/tsc.js:78686
throw e;
^
RangeError: Maximum call stack size exceeded
at getPromisedTypeOfPromise (/Users/okamoto-k/sandbox/node_modules/typescript/lib/tsc.js:49700:42)
at getAwaitedType (/Users/okamoto-k/sandbox/node_modules/typescript/lib/tsc.js:49758:32)
at getAwaitedType (/Users/okamoto-k/sandbox/node_modules/typescript/lib/tsc.js:49751:46)
at getAwaitedType (/Users/okamoto-k/sandbox/node_modules/typescript/lib/tsc.js:49767:35)
at getAwaitedType (/Users/okamoto-k/sandbox/node_modules/typescript/lib/tsc.js:49751:46)
at getAwaitedType (/Users/okamoto-k/sandbox/node_modules/typescript/lib/tsc.js:49767:35)
at getAwaitedType (/Users/okamoto-k/sandbox/node_modules/typescript/lib/tsc.js:49751:46)
at getAwaitedType (/Users/okamoto-k/sandbox/node_modules/typescript/lib/tsc.js:49767:35)
at getAwaitedType (/Users/okamoto-k/sandbox/node_modules/typescript/lib/tsc.js:49751:46)
at getAwaitedType (/Users/okamoto-k/sandbox/node_modules/typescript/lib/tsc.js:49767:35)
在线示例链接:
http://www.typescriptlang.org/play/#code/JYOwLgpgTgZghgYwgAgApQPYFtgGcICCCYwGIyEAHpCACa5qY74A8RJZAfMgN4C+AKDABPAA4p2pcgF5eI8QC5kuMFFABzPsgA+jbHkLEpAbgEIyK5AigQ4kAGIYMkssllxcwkAmQAKAJRK6PqsLiDc0tw8yPIQSgBEME7xyHymQA
相关问题:
未找到相关问题。
2条答案
按热度按时间qlckcl4x1#
你用你的定义制造了一个无限类型的循环:
PromiseAction
需要Action
,而Action
需要PromiseAction
。u4vypkhs2#
搜索词:promise,递归,崩溃,async?
你创建了一个无限类型的循环
是的,但编译器不应该因此崩溃。根据这种递归的形式,递归类型通常是可以接受的。这个看起来足够无害。
我想问题出在编译器如何评估
async
函数上。