Skip to content

Requesting "Extract to typedef" from within comment in type alias in JS file triggers a crash #48593

Description

Follow-up to #48540

type Foo = {
   /**
    * $
    */
   oops: string;
};

Request "extract to typedef" at $.

Response received: getEditsForRefactor (2477). Request took 2 ms. Success: false . Message: Error processing request. Debug Failure. False expression: Node must have a real position for this operation
Error: Debug Failure. False expression: Node must have a real position for this operation
    at NodeObject.assertHasRealPosition (node_modules/typescript/lib/tsserver.js:162217:22)
    at NodeObject.getStart (node_modules/typescript/lib/tsserver.js:162223:18)
    at processChildNode (node_modules/typescript/lib/tsserver.js:145833:47)
    at processChildNodes (node_modules/typescript/lib/tsserver.js:145934:48)
    at node_modules/typescript/lib/tsserver.js:145822:21
    at visitNodes (node_modules/typescript/lib/tsserver.js:30197:24)
    at Object.forEachChild (node_modules/typescript/lib/tsserver.js:30681:24)
    at processNode (node_modules/typescript/lib/tsserver.js:145819:20)
    at formatSpanWorker (node_modules/typescript/lib/tsserver.js:145619:17)
    at node_modules/typescript/lib/tsserver.js:145582:140
    at Object.getFormattingScanner (node_modules/typescript/lib/tsserver.js:144209:23)
    at Object.formatNodeGivenIndentation (node_modules/typescript/lib/tsserver.js:145582:31)
    at getFormattedTextOfNode (node_modules/typescript/lib/tsserver.js:148003:45)
    at format (node_modules/typescript/lib/tsserver.js:147974:52)
    at computeNewText (node_modules/typescript/lib/tsserver.js:147977:23)
    at node_modules/typescript/lib/tsserver.js:147941:39
    at Object.mapDefined (node_modules/typescript/lib/tsserver.js:605:30)
    at node_modules/typescript/lib/tsserver.js:147939:42
    at Object.mapDefined (node_modules/typescript/lib/tsserver.js:605:30)
    at Object.getTextChangesFromChanges (node_modules/typescript/lib/tsserver.js:147925:27)
    at ChangeTracker.getChanges (node_modules/typescript/lib/tsserver.js:147864:45)
    at Function.ChangeTracker.with (node_modules/typescript/lib/tsserver.js:147284:32)
    at Object.getRefactorEditsToExtractType [as getEditsForAction] (node_modules/typescript/lib/tsserver.js:160030:62)
    at Object.getEditsForRefactor (node_modules/typescript/lib/tsserver.js:148589:41)
    at Object.getEditsForRefactor (node_modules/typescript/lib/tsserver.js:164351:32)
    at IpcIOSession.Session.getEditsForRefactor (node_modules/typescript/lib/tsserver.js:175483:59)
    at Session.handlers.ts.Map.ts.getEntries._a.<computed> (node_modules/typescript/lib/tsserver.js:174103:61)
    at node_modules/typescript/lib/tsserver.js:175866:88
    at IpcIOSession.Session.executeWithRequestId (node_modules/typescript/lib/tsserver.js:175857:28)
    at IpcIOSession.Session.executeCommand (node_modules/typescript/lib/tsserver.js:175866:33)
    at IpcIOSession.Session.onMessage (node_modules/typescript/lib/tsserver.js:175892:35)
    at process.<anonymous> (node_modules/typescript/lib/tsserver.js:178527:31)
    at process.emit (node:events:390:28)
    at emit (node:internal/child_process:917:12)
    at processTicksAndRejections (node:internal/process/task_queues:84:21)

Activity

  1. added
    BugA bug in TypeScript
    Domain: JavaScriptThe issue relates to JavaScript specifically
    CrashFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad output
    Effort: CasualGood issue if you're already used to contributing to the codebase. Harder than "good first issue".
    Domain: LS: Refactoringse.g. extract to constant or function, rename symbol
    on Apr 6, 2022
  2. MQuy commented on Apr 6, 2022

    @MQuy
    Contributor

    which typescript version are you using? I tried with this testcase on master and it passes.

    // @allowJs: true
    // @Filename: a.js
    ////type Foo = {
    ////    /**
    ////     * /*a*/$/*b*/
    ////     */
    ////    oops: string;
    ////};
    
    goTo.file('a.js')
    goTo.select("a", "b");
    edit.applyRefactor({
        refactorName: "Extract type",
        actionName: "Extract to typedef",
        actionDescription: "Extract to typedef",
        newContent:
    `/**
     * @typedef {{
        oops: string;
    }} /*RENAME*/NewType
     */
    
    type Foo = NewType;`,
    });
  3. DanielRosenwasser commented on Apr 6, 2022

    @DanielRosenwasser
    MemberAuthor

    Hmm, you're right, it's because I'm using the nightly extension rather than the actual latest. Sorry!

  4. added
    DuplicateAn existing issue was already created
    and removed
    BugA bug in TypeScript
    Domain: LS: Refactoringse.g. extract to constant or function, rename symbol
    Domain: JavaScriptThe issue relates to JavaScript specifically
    CrashFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad output
    Effort: CasualGood issue if you're already used to contributing to the codebase. Harder than "good first issue".
    on Apr 6, 2022
  5. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions