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

Allow .d.ts files to represent anonymous class expressions with private members #36060

Open
trusktr opened this issue Jan 7, 2020 · 5 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@trusktr
Copy link
Contributor

trusktr commented Jan 7, 2020

Re-opening of #30355

That other issue is labeled "working as intended" so instead of this feature being a bug report, it is a feature request.

@RyanCavanaugh RyanCavanaugh changed the title False error TS4094: ... exported class expression may not be private or protected. Allow .d.ts files to represent anonymous class expressions with private members Jan 8, 2020
@RyanCavanaugh RyanCavanaugh added Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript labels Jan 8, 2020
@RyanCavanaugh
Copy link
Member

Wouldn't it be cool if this had some text in it?

@trusktr
Copy link
Contributor Author

trusktr commented Jan 20, 2020

It doesn't need, the other issue has details, but it is closed. I just think that this is a valid problem that is faced much too often by TS devs.

@web-padawan
Copy link

Related to #17293 (actually the same) - see #17293 (comment)

Related to #17744 - see my comment explaining why this is important #17744 (comment)

@RonnieLincoln
Copy link

RonnieLincoln commented Aug 28, 2022

any process?

Encountered this issue when trying Builder Pattern.

@MichaelMitchell-at
Copy link

MichaelMitchell-at commented May 26, 2024

This seems like it would be a way to annotate classes that have computed properties when using isolated declarations. Right now the only way to type this

export class Foo implements Iterable<number> {
  [Symbol.iterator]: () => {
  // ^ Computed property names on class or object literals cannot be inferred with --isolatedDeclarations.ts(9038)
    ...
  }
}

is to do something like

interface FooInstance extends Iterable<number> {}

interface FooClass {
  constructor(): FooInstance;
}

const _Foo = class {
  [Symbol.iterator]: () => {
    ...
  }
};

export const Foo: FooClass = _Foo;
export type Foo = FooInstance;

which is pretty verbose and doesn't quite have the exact same semantics in some cases.

If anonymous class types were allowed then we could perhaps do something like

export const Foo: class implements Iterable<number> {} = class {
  [Symbol.iterator]: () => {
    ...
  }
}

cc @dragomirtitian @weswigham

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants