-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Exported variable <variable name> has or is using private name <private name> #6307
Comments
It's because you're exporting export class Test {
constructor(public something: any){}
}
export let t = new Test("some thing"); |
@DanielRosenwasser thanks for your quick reply. While I understand your response I feel this is still an error because:
If there are currently constructs in the language already that address the use case that I've outlined above to a class then I apologize for my ignorance and hope you will point me in the right direction. Otherwise, wouldn't it be advisable to eliminate this error which seems to be guessing at the intention of a potential user and instead allow undefined/unresolved class errors to be flagged when users actually attempt to reference the class? Again, thank you for your response and have a very healthy and happy New Year. |
This error occurs when you use the Let's say you have this code: /// MyFile.ts
class Test {
// ... other members ....
constructor(public parent: Test){}
}
export let t = new Test("some thing"); To produce a declaration file, the compiler has to write out a type for /// MyFile.d.ts, auto-generated
export let t: ___fill in the blank___; The member In the very simplest cases, we could rewrite In general you shouldn't be using classes to implement a singleton pattern in TypeScript. See http://stackoverflow.com/questions/30174078/how-to-define-singleton-in-typescript |
@RyanCavanaugh you are correct, I am generating d.ts files for my project. |
Not sure if I should be asking this here, but this issue came up when I googled this error, I didn't quite feel like there was a solution, and to complicate matters further I've found other issues suggesting it once worked but now doesn't. So I'm trying to delve further into it and see if this issue might eventually describe the error case I'm hitting too.
So I'm importing
Then:
And then, of course, hitting the above error. This issue led me to believe I should be exporting EventEmitter, but every export method I tried resulted in no change. Further, I've found this issue which seems to imply that this is something entirely different. Here is a sample repo. I'm new enough to TS that I don't know whose issue that is to fix, but this issue seems to claim this error involves not exporting the superclass and nothing I've done fixes that. Everything else in my file compiles, and this only fails when I try to export my class and use its declarations. Thanks. |
@ndarilek can you file a new issue and provide a self containing repro. from a cursory look this looks like a bug, but i will have to look at the code to know for sure. |
Why does this error occur in react when used with typescript?
and the generated declaration file is:
Here I don't see why the interface needs to be exported at all . The required interface i.e. Also what is the difference between exporting the interface when it is declared i.e.
and exporting it as
The latter seems to throw the |
Exporting BaseInput as bundling TS build throws TS4020, see microsoft/TypeScript#6307
try this: Works if you don't bother taking the Test type to your d.ts declarations. |
I'm new to TypeScript, but using v2.3.4 this works for me: // pluggable-parsers.ts
interface IParserTree {
[index: string]: IParserNode
}
interface IParserNode {
[index: string]: IPluggableParser
}
export interface IPluggableParser {
(source: string, options: object): { code: string, map: string | object }
}
export interface IPluggableParsers {
require(parserPath: string, throwErrors: true): IPluggableParser | never
require(parserPath: string, throwErrors?: boolean): IPluggableParser | null
}
class PluggableParsers implements IPluggableParsers {
private readonly _parsers: IParserTree
constructor() {
this._parsers = {
html: {},
css: {},
js: {}
}
}
require(parserPath: string, throwErrors?: boolean) {
const [root, name] = parserPath.split('.')
const parser = this._parsers[root] && this._parsers[root][name] || null
if (!parser && throwErrors) {
throw new Error(`Parser ${parserPath} not found.`)
}
return parser
}
}
export default new PluggableParsers() as IPluggableParsers I got this // pluggable-parsers.d.ts export interface IPluggableParser {
(source: string, options: object): {
code: string;
map: string | object;
};
}
export interface IPluggableParsers {
require(parserPath: string, throwErrors: true): IPluggableParser | never;
require(parserPath: string, throwErrors?: boolean): IPluggableParser | null;
}
declare const _default: IPluggableParsers;
export default _default; ...and this pluggable-parsers.js var PluggableParsers = (function () {
function PluggableParsers() {
this._parsers = {
html: {},
css: {},
js: {}
};
}
PluggableParsers.prototype.require = function (parserPath, throwErrors) {
var _a = parserPath.split('.'), root = _a[0], name = _a[1];
var parser = this._parsers[root] && this._parsers[root][name] || null;
if (!parser && throwErrors) {
throw new Error("Parser " + parserPath + " not found.");
}
return parser;
};
return PluggableParsers;
}());
export default new PluggableParsers(); Transpiled and ready to be processed by Rollup. |
Why can't
This behaviour surprised me when generating declaration files for react classes - it requires you to export the |
I'm curious why every interface must be exported if referenced by any other exported object as well. With large react-redux projects it leads to an enormous proliferation of exported interfaces, each of which must have their own unique names. |
Came here to point that you might get this error because of in correct order in export statement. I was getting ` error for following code:
Solution Need to change the export order
|
Should this issue be reopened? It seems that it affects many people and the workaround impacts public interfaces of modules which is not ideal. On the other hand, apparently, fixing this shouldn't require major changes to the emitted declarations. The referenced unexported symbols do already get declared. Minimal reproduction:
Expected:
Indeed, a user of Note that unexported types do get written to declaration files. E.g. if |
* Re-type `helper` from @ember/component/helper Previous typing caused an error about using private name `Ember.Helper` when generating declaration files. Fortunately, the previous typings were incorrect anyway, so we can remove the reference to `Ember.Helper` and thus fix the issue. Relevant links: * microsoft/TypeScript#5711 * microsoft/TypeScript#6307 * https://www.emberjs.com/api/ember/2.18/functions/@ember%2Fcomponent%2Fhelper/helper * https://github.com/emberjs/ember.js/blob/v2.18.2/packages/ember-glimmer/lib/helper.ts#L120 * Add test for `helper` from @ember/component/helper
The following code:
produces the following error:
Exported variable 't' has or is using private name 'Test'.
The text was updated successfully, but these errors were encountered: