Skip to content

getChildren() includes synthetic NodeObjects, that can't easily be discerned from RemoteNodesΒ #64483

Description

@Qjuh

πŸ”Ž Search Terms

synthetic, NodeObject, RemoteNode, getChildren()

πŸ•— Version & Regression Information

  • This changed between versions 6 and 7.1

⏯ Playground Link

No response

πŸ’» Code

index.d.ts

export declare class Client  {
    constructor(options?: Record<string, unknown>);
}
import {API} from 'typescript/unstable/api/sync';
import type {Declaration} from 'typescript/unstable/ast';
const program = new API().createProgram('./index.d.ts', {});
const checker = program.getProject().checker;
const getSymbol = (child: Declaration) => [checker.getSymbolAtLocation(child), child.getChildren().map(getSymbol)];
console.log(getSymbol(program.getSourcefile('./index.d.ts'));

πŸ™ Actual behavior

Error: getNodeId requires a RemoteNode
when facing the synthetic node for the constructor keyword:

NodeObject {
  kind: 136,
  flags: 0,
  pos: 2216,
  end: 2232,
  parent: [RemoteNode],
  _data: undefined
}

πŸ™‚ Expected behavior

getChildren() only returns nodes that can either be used like any other RemoteNode or at least have a flag or isRemoteNode() typeguard to handle accordingly.

Additional information about the issue

Started as discussion in https://discord.com/channels/508357248330760243/640177429775777792/1553810176790765731

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions