-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Difficulties with --declaration flag (error TS4025: Exported variable has or is using private name) #23110
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
Comments
For background, the declaration emitter will not add an import to a module that was not originally imported; nor would it make a declaration that was previously un-exported exported. that is why it requires the user to import a module or export a declaration if it is needed to write the type of a declaration in the current file. For more information see #9944. The expected fix when you see errors about unexported declaration is one of two things, either 1. export the declaration in question, or 2. write an explicit type annotation for the declaration that is exported and is using the unexported declaration. in the example above, your declaration of export interface IBindable {}
function htmlBind (el: JQuery|HTMLElement, options?: string | html.Options): IBindable {}
export const html: (el: JQuery|HTMLElement, options?: string | html.Options) => IBindable = htmlBind;
export namespace html {
export interface Options {
}
} |
Ok, it's clear, thanks.
this makes sense. just another example: class TreeNode {}
class Tree {
Node: typeof TreeNode;
}
Tree.prototype.Node = TreeNode;
namespace Tree {
export import Node = TreeNode;
}
export = Tree; that class Tree {
Node: typeof Tree.TreeNode;
}
Tree.prototype.Node = Tree.TreeNode;
namespace Tree {
export class TreeNode {}
} I seems very naturally to declare a type alias on root and continue to use short name (at least for type): type TreeNode = Tree.TreeNode; but it won't work. It's already was suggested in #14286. So my +1. It'd help a lot. |
it is. the intention is to warn you about exposing internal implementation details. it is possible you want to expose this as |
The underlying issue here is that originally we took a more strict interpretation of visibility.. the definition really meant that the user of the API can refer to the type name. in this case |
Filed #23127 to track that. |
Thanks, let me clarify a bit. type TreeNode = Tree.TreeNode;
class Tree {
Node: typeof TreeNode;
function addNode(node: TreeNode) {}
}
namespace Tree {
export class TreeNode {
title: string;
data: any;
}
}
export = Tree; will we get a declaration where |
yes. your .d.ts file will have the type. but your users will not be able to use the type name |
I think Symbol.for(...) should not be wrong! |
I'm trying to compile my lib with
--declaration
flag. As it's the only officially approved way to distribute libraries. But I'm having lots of errors from the compiler.In general all errors are related to different visibility of elements. But error codes are different depending on context. But mostly errors are (examples):
error TS4025: Exported variable 'html' has or is using private name 'htmlBind'.
error TS4031: Public property '_currentArea' of exported class has or is using private name 'AreaInternal'.
error TS4055: Return type of public method from exported class has or is using private name 'PartHelper'.
error TS4073: Parameter 'partHelper' of public method from exported class has or is using private name 'PartHelper'.
error TS4078: Parameter 'options' of exported function has or is using private name 'ExtendOptions'.
Mostly of them makes sense, but not all.
Here I'd like to discuss TS4025.
I have a module with a local function which isn't exported. I want to export it under another name.
but here TSC produces the error:
binding.ts(527,14): error TS4025: Exported variable 'html' has or is using private name 'htmlBind'.
Of cause I could name the function as
html
and export:But inside the module I'd like to use other (more specific) name.
What I actually need to do is to export function as a separate statement, like (doesn't work)
Also in other cases I have similar problem for namespaces (instead of function). I want to declare a namespace and then export it.
Given a module with
export=
This fails to compile with error TS4031: Public property 'utils' of exported class has or is using private name 'indexedDBUtils'.
So I have to export the namespace
indexedDBUtils
.The problem is that now I have to use very long identifiers like
DataStoreIndexedDB.indexedDBUtils.isSupported
.It'd be nice to declare namespace as before and then export it (doesn't work):
The text was updated successfully, but these errors were encountered: