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

Missing computed properties in declaration emit #61068

Open
DanielRosenwasser opened this issue Jan 28, 2025 · 1 comment
Open

Missing computed properties in declaration emit #61068

DanielRosenwasser opened this issue Jan 28, 2025 · 1 comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@DanielRosenwasser
Copy link
Member

With #60052, we now emit qualified names rather than generate an index signature for computed names in classes; however, this now puts us in an awkward place where regardless of errors, declaration emit diverges on isolatedDeclarations.

Playground Links:

export const greeting: unique symbol = Symbol();
export const count: unique symbol = Symbol();

export class MyClass1 {
    [greeting]: string = "world";
    [count]: number = 42;
}

export enum PropertyNames {
    greeting = "greeting",
    count = "count",
}

export class MyClass2 {
    [PropertyNames.greeting]: string = "world";
    [PropertyNames.count]: number = 42;
}

export let prop!: string;

export class MyClass3 {
    [prop]: () => void = () => {}
}

Compared to --isolatedDeclarations false The declaration emit lacks expected contents in MyClass1 and MyClass2:

  export declare const greeting: unique symbol;
  export declare const count: unique symbol;
  export declare class MyClass1 {
-     [greeting]: string;
-     [count]: number;
  }
  export declare enum PropertyNames {
      greeting = "greeting",
      count = "count"
  }
  export declare class MyClass2 {
-     [PropertyNames.greeting]: string;
-     [PropertyNames.count]: number;
  }
  export declare let prop: string;
  export declare class MyClass3 {
      [prop]: () => void;
  }

It is surprising that prop is emitted regardless of --isolatedDeclarations, but not the other contents.

@DanielRosenwasser DanielRosenwasser added In Discussion Not yet reached consensus Suggestion An idea for TypeScript labels Jan 28, 2025
@DanielRosenwasser
Copy link
Member Author

After talking to people on our side, the assessment is

  1. It would be nice if these divergences didn't exist
  2. but they're okay because emit in the face of errors is sort of undefined behavior
  3. though it's pretty weird that we wouldn't do the most obvious syntactic thing
  4. but it might be fine regardless because @weswigham is working on allowing computed properties to work in isolatedDeclarations.

So if someone wants to correct the divergence, great! Otherwise, this should be fixed in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

1 participant