Skip to content

Extract to typedef from (invalid) type with comments in JS file causes assertion failure #48540

Description

// @filename: foo.js
type Foo = [|{
    /**
     * 
     */
    oops: string;
}|];

// @filename: bar.js
type Bar = [|string | /* oops */ boolean|];

Request "extract to typedef" on each[|region|].

Response received: getEditsForRefactor (194). 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_DIR]/typescript/lib/tsserver.js:162180:22)
    at NodeObject.getStart ([NODE_MODULES_DIR]/typescript/lib/tsserver.js:162186:18)
    at processChildNode ([NODE_MODULES_DIR]/typescript/lib/tsserver.js:145804:47)
    at processChildNodes ([NODE_MODULES_DIR]/typescript/lib/tsserver.js:145905:48)
    at [NODE_MODULES_DIR]/typescript/lib/tsserver.js:145793:21
    at visitNodes ([NODE_MODULES_DIR]/typescript/lib/tsserver.js:30193:24)
    at Object.forEachChild ([NODE_MODULES_DIR]/typescript/lib/tsserver.js:30677:24)
    at processNode ([NODE_MODULES_DIR]/typescript/lib/tsserver.js:145790:20)
    at formatSpanWorker ([NODE_MODULES_DIR]/typescript/lib/tsserver.js:145590:17)
    at [NODE_MODULES_DIR]/typescript/lib/tsserver.js:145553:140
    at Object.getFormattingScanner ([NODE_MODULES_DIR]/typescript/lib/tsserver.js:144180:23)
    at Object.formatNodeGivenIndentation ([NODE_MODULES_DIR]/typescript/lib/tsserver.js:145553:31)
    at getFormattedTextOfNode ([NODE_MODULES_DIR]/typescript/lib/tsserver.js:147971:45)
    at format ([NODE_MODULES_DIR]/typescript/lib/tsserver.js:147942:52)
    at computeNewText ([NODE_MODULES_DIR]/typescript/lib/tsserver.js:147945:23)
    at [NODE_MODULES_DIR]/typescript/lib/tsserver.js:147909:39
    at Object.mapDefined ([NODE_MODULES_DIR]/typescript/lib/tsserver.js:605:30)
    at [NODE_MODULES_DIR]/typescript/lib/tsserver.js:147907:42
    at Object.mapDefined ([NODE_MODULES_DIR]/typescript/lib/tsserver.js:605:30)
    at Object.getTextChangesFromChanges ([NODE_MODULES_DIR]/typescript/lib/tsserver.js:147893:27)
    at ChangeTracker.getChanges ([NODE_MODULES_DIR]/typescript/lib/tsserver.js:147832:45)
    at Function.ChangeTracker.with ([NODE_MODULES_DIR]/typescript/lib/tsserver.js:147252:32)
    at Object.getRefactorEditsToExtractType [as getEditsForAction] ([NODE_MODULES_DIR]/typescript/lib/tsserver.js:159993:62)
    at Object.getEditsForRefactor ([NODE_MODULES_DIR]/typescript/lib/tsserver.js:148557:41)
    at Object.getEditsForRefactor ([NODE_MODULES_DIR]/typescript/lib/tsserver.js:164314:32)
    at IpcIOSession.Session.getEditsForRefactor ([NODE_MODULES_DIR]/typescript/lib/tsserver.js:175446:59)
    at Session.handlers.ts.Map.ts.getEntries._a.<computed> ([NODE_MODULES_DIR]/typescript/lib/tsserver.js:174066:61)
    at [NODE_MODULES_DIR]/typescript/lib/tsserver.js:175829:88
    at IpcIOSession.Session.executeWithRequestId ([NODE_MODULES_DIR]/typescript/lib/tsserver.js:175820:28)
    at IpcIOSession.Session.executeCommand ([NODE_MODULES_DIR]/typescript/lib/tsserver.js:175829:33)
    at IpcIOSession.Session.onMessage ([NODE_MODULES_DIR]/typescript/lib/tsserver.js:175855:35)
    at process.<anonymous> ([NODE_MODULES_DIR]/typescript/lib/tsserver.js:178490: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: 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 3, 2022
  2. rbuckton commented on Apr 4, 2022

    @rbuckton
    Contributor

    I was encountering a similar error in #48112 due to new synthetic nodes being added as a result of processing text changes. I fixed the case I ran into using this: https://github.com/microsoft/TypeScript/pull/48112/files?show-viewed-files=true&file-filters%5B%5D=#diff-386d93db50a938da0c4af7bb293ac679b5da235cebeeee9adbc040fbf8aa222cR1128-R1136

    I'll have to check whether the issues are related.

  3. DanielRosenwasser commented on Apr 4, 2022

    @DanielRosenwasser
    MemberAuthor

    That link seems to have issues on my end - can you hard-link to the line range of the file?

  4. rbuckton commented on Apr 4, 2022

    @rbuckton
    Contributor

    const textChangesTransformationContext: TransformationContext = {
    ...nullTransformationContext,
    factory: createNodeFactory(
    nullTransformationContext.factory.flags | NodeFactoryFlags.NoParenthesizerRules,
    nullTransformationContext.factory.baseFactory),
    };
    export function assignPositionsToNode(node: Node): Node {
    const visited = visitEachChild(node, assignPositionsToNode, textChangesTransformationContext, assignPositionsToNodeArray, assignPositionsToNode);

  5. rbuckton commented on Apr 4, 2022

    @rbuckton
    Contributor

    The problem is that the nullTransformationContext uses a default NodeFactory that does auto-parenthesization, and our auto-parenthesization for types is fairly aggressive, so we sometimes introduce a new parenthesized type when visiting on 1136. Since this visitor is only supposed to create a proxy for existing nodes for the purpose of setting positions, its not designed to handle net-new nodes.

  6. DanielRosenwasser commented on Apr 5, 2022

    @DanielRosenwasser
    MemberAuthor

    Is it a parenthesization issue? It seems more like it's specific to putting a comment inside of a comment. The fix that Minh Quy (@MQuy) has at #48545 of just dropping the comments fixes the specific tests at a shallow level, but would fail any deeper.

    Is there a way to turn off comment trivia emit for an entire subtree? That would probably be an ideal fix, but admittedly I'm not familiar with the transform pipeline anymore.

  7. rbuckton commented on Apr 5, 2022

    @rbuckton
    Contributor

    Is it a parenthesization issue? It seems more like it's specific to putting a comment inside of a comment. The fix that Minh Quy (@MQuy) has at #48545 of just dropping the comments fixes the specific tests at a shallow level, but would fail any deeper.

    I thought it may have been due to a ParenthesizedType node being silently added to the type, but that does not seem to be the case here.

    Is there a way to turn off comment trivia emit for an entire subtree? That would probably be an ideal fix, but admittedly I'm not familiar with the transform pipeline anymore.

    Yes, you can set EmitFlags.NoComments | EmitFlags.NoNestedComments to disable comments for the node and its subtree.

  8. DanielRosenwasser commented on Apr 5, 2022

    @DanielRosenwasser
    MemberAuthor

    Thank you Minh Quy (@MQuy)!

  9. DanielRosenwasser commented on Apr 6, 2022

    @DanielRosenwasser
    MemberAuthor

    Looks like there's still an issue when triggering the command from inside of a comment (#48593).

  10. 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

    BugA bug in TypeScriptCrashFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad outputDomain: JavaScriptThe issue relates to JavaScript specificallyDomain: LS: Refactoringse.g. extract to constant or function, rename symbolEffort: CasualGood issue if you're already used to contributing to the codebase. Harder than "good first issue".Help WantedYou can do this

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions