Skip to content

ExpressionWithTypeArguments.insertTypeArguments crashes on mixins #1615

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

Open
maxpatiiuk opened this issue Feb 16, 2025 · 0 comments
Open

ExpressionWithTypeArguments.insertTypeArguments crashes on mixins #1615

maxpatiiuk opened this issue Feb 16, 2025 · 0 comments

Comments

@maxpatiiuk
Copy link

Trying to call .addTypeArguments() on a ExpressionWithTypeArguments that contains a mixin results in an exception:

/Users/mak13180/site/esri/arcgis-web-components-3/node_modules/@ts-morph/common/dist/ts-morph-common.js:438
            throw new InvalidOperationError(typeof errorMessage === "string" ? errorMessage : errorMessage(), node);
                  ^

InvalidOperationError: A child of the kind Identifier was expected.

/Users/mak13180/site/esri/arcgis-web-components-3/packages/support-packages/jsapi-extractor/test.ts:1:17
> 1 | class A extends B(C) {}
    at Object.throwIfNullOrUndefined (/Users/mak13180/site/esri/arcgis-web-components-3/node_modules/@ts-morph/common/dist/ts-morph-common.js:438:19)
    at ExpressionWithTypeArguments.getFirstChildByKindOrThrow (/Users/mak13180/site/esri/arcgis-web-components-3/node_modules/ts-morph/dist/ts-morph.js:3857:30)
    at ExpressionWithTypeArguments.insertTypeArguments (/Users/mak13180/site/esri/arcgis-web-components-3/node_modules/ts-morph/dist/ts-morph.js:10126:41)
    at ExpressionWithTypeArguments.addTypeArguments (/Users/mak13180/site/esri/arcgis-web-components-3/node_modules/ts-morph/dist/ts-morph.js:10115:25)
    at <anonymous> (/Users/mak13180/site/esri/arcgis-web-components-3/packages/support-packages/jsapi-extractor/src/temp.ts:11:14)
    at ModuleJob.run (node:internal/modules/esm/module_job:271:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:547:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:116:5)

Node.js v22.12.0

Version: 25.0.1

To Reproduce

import { Project, SyntaxKind } from "ts-morph";

const project = new Project();
const sourceFile = project.createSourceFile("test.ts", "class A extends B(C) {}");
const expression = sourceFile.getFirstDescendantByKindOrThrow(SyntaxKind.ExpressionWithTypeArguments);
expression.addTypeArguments(["D"]);

Expected behavior

No exception should occur.
Source file should be modified to look as follows:

class A extends B(C)<D> {}

Workaround

Use .replaceText():

  expression.replaceWithText(`${expression.getText()}<D>`);

Extra details

Bug occurs here:

const identifier = this.getFirstChildByKindOrThrow(SyntaxKind.Identifier);

Code should be modified to handle the case that TypeArgumentedNode contains something other than identifier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant