Skip to content

RangeError: Maximum call stack size exceeded #23661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jwalton opened this issue Apr 24, 2018 · 0 comments · Fixed by #23808
Closed

RangeError: Maximum call stack size exceeded #23661

jwalton opened this issue Apr 24, 2018 · 0 comments · Fixed by #23808
Assignees
Labels
Bug A bug in TypeScript

Comments

@jwalton
Copy link

jwalton commented Apr 24, 2018

TypeScript Version: 2.8.3

Code

export interface IValidationError {
    message: string;
}

export default class Operation {
    validateParameters(parameterValues: any) : IValidationError[] | null {
        let result: IValidationError[] | null = null;
        for(const parameterLocation of Object.keys(parameterValues)) {
            const parameter: any = (this as any).getParameter();;
            const values = (this as any).getValues();

            const innerResult = parameter.validate(values[parameter.oaParameter.name]);
            if(innerResult && innerResult.length > 0) {
                // Commenting out this line will fix the problem.
                result = (result || []).concat(innerResult);
            }
        }

        return result;
    }
}```

tsconfig.json:

```json
{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "lib": ["es6"],
        "allowJs": false,
        "declaration": true,
        "declarationDir": "./types",
        "sourceMap": true,
        "outDir": "./lib",
        "stripInternal": true,

        "strict": true,
        "noImplicitAny": true,
        "noImplicitThis": true,
        "alwaysStrict": true,

        "forceConsistentCasingInFileNames": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "noImplicitReturns": true,
        "noFallthroughCasesInSwitch": true,

        "typeRoots": [
            "./node_modules/@types",
            "./@types"
        ],
        "esModuleInterop": true
    },
    "include": [
        "./src/**/*"
    ],
    "compileOnSave": true
}

Expected behavior:

Compile this into JS.

Actual behavior:

RangeError: Maximum call stack size exceeded
    at /Users/jwalton/.nvm/versions/node/v8.11.1/lib/node_modules/typescript/lib/tsc.js:31413:53
    at Object.findAncestor (/Users/jwalton/.nvm/versions/node/v8.11.1/lib/node_modules/typescript/lib/tsc.js:343:26)
    at isInsideFunction (/Users/jwalton/.nvm/versions/node/v8.11.1/lib/node_modules/typescript/lib/tsc.js:31413:25)
    at checkNestedBlockScopedBinding (/Users/jwalton/.nvm/versions/node/v8.11.1/lib/node_modules/typescript/lib/tsc.js:31422:34)
    at checkIdentifier (/Users/jwalton/.nvm/versions/node/v8.11.1/lib/node_modules/typescript/lib/tsc.js:31349:13)
    at checkExpressionWorker (/Users/jwalton/.nvm/versions/node/v8.11.1/lib/node_modules/typescript/lib/tsc.js:35793:28)
    at checkExpression (/Users/jwalton/.nvm/versions/node/v8.11.1/lib/node_modules/typescript/lib/tsc.js:35769:42)
    at checkExpressionCached (/Users/jwalton/.nvm/versions/node/v8.11.1/lib/node_modules/typescript/lib/tsc.js:35672:38)
    at getTypeOfExpression (/Users/jwalton/.nvm/versions/node/v8.11.1/lib/node_modules/typescript/lib/tsc.js:35754:28)
    at getContextualTypeForBinaryOperand (/Users/jwalton/.nvm/versions/node/v8.11.1/lib/node_modules/typescript/lib/tsc.js:31916:25)

Playground Link: https://www.typescriptlang.org/play/#src=export%20interface%20IValidationError%20%7B%0D%0A%20%20%20%20message%3A%20string%3B%0D%0A%7D%0D%0A%0D%0Aexport%20default%20class%20Operation%20%7B%0D%0A%20%20%20%20validateParameters(parameterValues%3A%20any)%20%3A%20IValidationError%5B%5D%20%7C%20null%20%7B%0D%0A%20%20%20%20%20%20%20%20let%20result%3A%20IValidationError%5B%5D%20%7C%20null%20%3D%20null%3B%0D%0A%20%20%20%20%20%20%20%20for(const%20parameterLocation%20of%20Object.keys(parameterValues))%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20const%20parameter%3A%20any%20%3D%20(this%20as%20any).getParameter()%3B%3B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20const%20values%20%3D%20(this%20as%20any).getValues()%3B%0D%0A%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20const%20innerResult%20%3D%20parameter.validate(values%5Bparameter.oaParameter.name%5D)%3B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20if(innerResult%20%26%26%20innerResult.length%20%3E%200)%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20result%20%3D%20(result%20%7C%7C%20%5B%5D).concat(innerResult)%3B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0D%0A%20%20%20%20%20%20%20%20%7D%0D%0A%0D%0A%20%20%20%20%20%20%20%20return%20result%3B%0D%0A%20%20%20%20%7D%0D%0A%7D

This passes in playground.

Related Issues:

@mhegazy mhegazy added the Bug A bug in TypeScript label Apr 25, 2018
@mhegazy mhegazy added this to the TypeScript 2.9 milestone Apr 25, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants