Skip to content
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

ExportedDeclarations type union is missing type BindingElement #1499

Open
velut opened this issue Feb 1, 2024 · 0 comments
Open

ExportedDeclarations type union is missing type BindingElement #1499

velut opened this issue Feb 1, 2024 · 0 comments

Comments

@velut
Copy link

velut commented Feb 1, 2024

Describe the bug

Version: 21.0.1

The ExportedDeclarations type union is missing the type BindingElement which can be returned when an export declaration uses object or array destructuring, for example:

// Export with object destructuring.
export const {
    foo,
    bar: baz,
    ...qux
} = {
    foo: "hello",
    bar: 42,
    quxA: 1, quxB: 2, quxC: 3
} as const;

// Export with array destructuring.
export const [aaa, bbb, ...[ccc, ddd]] = [1, 2, 3, 4] as const;

To Reproduce

import { Project } from "ts-morph";

const project = new Project({ useInMemoryFileSystem: true });

const sourceFile = project.createSourceFile(
  "test.ts",
  `
// Export with object destructuring.
export const {
    foo,
    bar: baz,
    ...qux
} = {
    foo: "hello",
    bar: 42,
    quxA: 1, quxB: 2, quxC: 3
} as const;

// Export with array destructuring.
export const [aaa, bbb, ...[ccc, ddd]] = [1, 2, 3, 4] as const;
`,
);

for (const [exportName, declarations] of sourceFile.getExportedDeclarations()) {
  for (const declaration of declarations) {
    console.log({
      exportName,
      kind: declaration.getKindName(), // All declarations are of kind `BindingElement`
      type: declaration.getType().getText(),
    });
  }
}

Output:

{
  exportName: "foo",
  kind: "BindingElement",
  type: "\"hello\"",
}
{
  exportName: "baz",
  kind: "BindingElement",
  type: "42",
}
{
  exportName: "qux",
  kind: "BindingElement",
  type: "{ quxA: 1; quxB: 2; quxC: 3; }",
}
{
  exportName: "aaa",
  kind: "BindingElement",
  type: "1",
}
{
  exportName: "bbb",
  kind: "BindingElement",
  type: "2",
}
{
  exportName: "ccc",
  kind: "BindingElement",
  type: "3",
}
{
  exportName: "ddd",
  kind: "BindingElement",
  type: "4",
}

Expected behavior

ExportedDeclarations type union should include type BindingElement.

Thank you for your time!

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