我得到以下错误:
ERROR in RangeError: Maximum call stack size exceeded
at getResolvedBaseConstraint (/project/node_modules/typescript/lib/typescript.js:53262:43)
at getBaseConstraintOfType (/project/node_modules/typescript/lib/typescript.js:53242:34)
at getTypeFacts (/project/node_modules/typescript/lib/typescript.js:62711:37)
at getTypeFacts (/project/node_modules/typescript/lib/typescript.js:62711:24)
at getTypeFacts (/project/node_modules/typescript/lib/typescript.js:62711:24)
at getTypeFacts (/project/node_modules/typescript/lib/typescript.js:62711:24)
at getTypeFacts (/project/node_modules/typescript/lib/typescript.js:62711:24)
at getTypeFacts (/project/node_modules/typescript/lib/typescript.js:62711:24)
at getTypeFacts (/project/node_modules/typescript/lib/typescript.js:62711:24)
at getTypeFacts (/project/node_modules/typescript/lib/typescript.js:62711:24)
at getTypeFacts (/project/node_modules/typescript/lib/typescript.js:62711:24)
at getTypeFacts (/project/node_modules/typescript/lib/typescript.js:62711:24)
at getTypeFacts (/project/node_modules/typescript/lib/typescript.js:62711:24)
at getTypeFacts (/project/node_modules/typescript/lib/typescript.js:62711:24)
at getTypeFacts (/project/node_modules/typescript/lib/typescript.js:62711:24)
at getTypeFacts (/project/node_modules/typescript/lib/typescript.js:62711:24)
我有以下几点 global.d.ts
:
declare type UserId = `${number}`;
declare interface DevEnvironment {
dev?: {
user?: {
userId?: UserId;
}
}
}
在上面的界面中,如果我更改 userId?: UserId
到 userId?: string
,则上述错误消失。我认为这是因为这个模板文字错误。
然而,我是这样使用上述内容的;在这里,我正在开发环境中构建环境文件:
let dev = {};
try {
// The below file may or may not exists depending on the environment
dev = require('./environment.local').dev;
} catch (e) { }
export const environment = Object.assign({}, {
// Main environment variables
}, {dev: dev || {}} as DevEnvironment);
然后,我将其用于服务:
@Injectable({ providedIn: 'root' })
export class User {
get userId(): UserId {
const defaultValue = (environment.dev?.user?.userId || '000000000') as UserId;
}
}
我知道这个问题据说已经在较新版本的typescript中得到了修复,但我们仍然坚持使用 4.1.5
由于使用angular 11 cli,如下所示:
$ npm i typescript@^4.2.0
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: @angular/compiler-cli@11.2.14
npm ERR! node_modules/@angular/compiler-cli
npm ERR! dev @angular/compiler-cli@"^11.2.11" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/compiler-cli@"^10.0.0" from @angular-devkit/build-angular@0.1002.3
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR! @angular-devkit/build-angular@">=0.1000.0 < 0.1100.0" from @angular-builders/custom-webpack@10.0.1
npm ERR! node_modules/@angular-builders/custom-webpack
npm ERR! dev @angular-builders/custom-webpack@"^10.0.1" from the root project
npm ERR! dev @angular-devkit/build-angular@"^0.1002.3" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /Users/rnaddy/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/rnaddy/.npm/_logs/2021-07-08T15_28_45_346Z-debug.log
我可以做些什么来使用我最初想要使用的语法吗?
1条答案
按热度按时间1zmg4dgp1#
这是一个内部的typescript错误,对我来说是生产工作,但不是开发。
按照建议更新typescript,即使它的输出不完全相同,但问题是相同的。
我不知道哪一个版本能真正工作,我最终得到了4.x.x版本,并且神奇地按照预期工作。