Description
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.
export interface IBindable {}
function htmlBind (el: JQuery|HTMLElement, options?: string | html.Options): IBindable {}
export const html = htmlBind;
export namespace html {
export interface Options {
}
}
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:
export function html {}
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)
export htmlBind as html;
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=
namespace indexedDBUtils {
export const isSupported: boolean = !!window.indexedDB;
}
class DataStoreIndexedDB {
utils: typeof indexedDBUtils;
}
DataStoreIndexedDB.mixin({
utils: indexedDBUtils
});
export = DataStoreIndexedDB;
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
.
class DataStoreIndexedDB {
utils: typeof DataStoreIndexedDB.indexedDBUtils;
}
namespace DataStoreIndexedDB {
export namespace indexedDBUtils {
export const isSupported: boolean = !!window.indexedDB;
}
}
DataStoreIndexedDB.mixin({
utils: DataStoreIndexedDB.indexedDBUtils
});
export = DataStoreIndexedDB ;
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):
namespace indexedDBUtils {
export const isSupported: boolean = !!window.indexedDB;
}
class DataStoreIndexedDB {
utils: typeof indexedDBUtils;
}
namespace DataStoreIndexedDB {
export indexedDBUtils;
}
DataStoreIndexedDB.mixin({
utils: indexedDBUtils
});