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

TS4082: Default export of the module has or is using private name 'Ember.Helper' #133

Closed
dfreeman opened this issue Feb 20, 2018 · 10 comments
Labels
bug types:core Something is wrong with the Ember type definitions

Comments

@dfreeman
Copy link
Member

When trying to generate declarations for an addon that exposes a helper with any of the 2.8 series of @types/ember releases, I see the following error:

TS4082: Default export of the module has or is using private name 'Ember.Helper'

To reproduce:

ember addon my-addon --yarn && cd my-addon
ember install ember-cli-typescript
ember generate helper foo
ember ts:precompile
@chriskrycho
Copy link
Member

chriskrycho commented Feb 20, 2018

How is it imported? Looks public here and it's just a normal class here. 🤔

@dfreeman
Copy link
Member Author

import { helper } from '@ember/component/helper';

export function fooHelper(params/*, hash*/) {
  return params;
}

export default helper(fooHelper);

@dfreeman
Copy link
Member Author

There's been a bunch of motion in the past couple weeks to make the declaration emitter more helpful in these kinds of scenarios, but it looks like for names in other modules, things are still open: microsoft/TypeScript#9944.

In the meantime, the workaround here is to change that import to import Helper, { helper } from '@ember/component/helper';, though that won't play nicely with the noUnusedLocals lint.

@chriskrycho
Copy link
Member

Oh, 🤦‍♂️ – I finally understand the privacy problem here. (For other readers who may have been confused: it's because in the specific context of the module @ember/component/helper, the class Ember.Helper itself isn't public – it's public elsewhere, and another type which is equivalent to it is also public, but that type is private in the module.

Ugh.

@dfreeman
Copy link
Member Author

🎉 Looks like this will be fixed in TS 2.9 microsoft/TypeScript#24071

@dfreeman
Copy link
Member Author

dfreeman commented Jun 10, 2018

This may or may not actually be fixed by more recent TS releases, but at some point we solved this particular problem by declaring the return type of helper in @types/ember to just be any.

The overall problem still exists in both 2.9 and most 3.0 beta I checked (3.0.0-dev.20180609), as evidenced by alexlafroscia/ember-react-components#8. We may want to consider documenting workarounds for this issue more generally or, if someone has the time, investigating what it would take to solve the problem upstream in tsc with import types.

@Roustalski
Copy link

Not sure if this is helpful in the context of Ember, but a google search brought me here when facing the same issue.

In react land, if I have something like this:

src/somefile.ts

import * as React from 'react';

export default class BlahBlah extends React.Component<Models.Props> {
...

I get the same error message: [ts] Default export of the module has or is using private name 'React.ComponentClass'. when importing BlahBlah from ./somefile, which means that somefile exposes its private reference to React. I solved this by re-exporting React from somefile:

import * as React from 'react';

export { React };

export default class Login extends React.Component<Models.Props> {
...

@n8agrin
Copy link

n8agrin commented Jul 5, 2018

I'm having the same problem you describe @Roustalski. I wrote up an attempt at a repro here microsoft/TypeScript#24071 (comment)

FWIW your solution does work for me, but I'd much rather not have to instruct engineers on the how and why they need to re-export variables and instead let the Typescript compiler do that for them.

@chriskrycho chriskrycho added the types:core Something is wrong with the Ember type definitions label Jul 6, 2018
@mike-north mike-north added the bug label Sep 6, 2018
@trusktr
Copy link

trusktr commented Dec 21, 2019

I've opened a request to fix issues like these in TypeScript by bringing declaration files to parity with language features. microsoft/TypeScript#35822

@chriskrycho
Copy link
Member

Long since resolved by fixing type declarations in DefinitelyTyped and – more importantly – publishing types from Ember’s source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug types:core Something is wrong with the Ember type definitions
Projects
Status: Closed (complete or no action taken)
Development

No branches or pull requests

6 participants