-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Thrown "error TS4022: 'extends' clause of exported interface '...' has or is using private name ..." with --declaration flag and mixing imported export name with equal export interface name #16440
Comments
Any suggestions yet? I really need this for my project and would appreciate any tips to overcome this problem. Is this a bug or have I just forgotten something? |
Can you try changing In other words, rename |
Thank you for quick response but if you mean this: import * as R from './Response';
export { R as Response };
export interface Response {
message: R.Message;
}
export interface TypedResponse extends Response {
type: string;
message: R.Message;
} sadly not resolves the problem. If you meant this: import * as R from './Response';
export { R };
export interface Response {
message: R.Message;
}
export interface TypedResponse extends Response {
type: string;
message: R.Message;
} and using it that way: import * as Service from './Service';
class MySuccessMessage implements Service.R.Message ...
class MyResponse implements Service.Response ...
... bypasses the problem but thats the whole point here, that I try to merge the reexported "Response"-module-namespace with the equal named interface to get a nice hierarchical structure which I can use like this: import * as Service from './Service';
class MySuccessMessage implements Service.Response.Message ...
class MyResponse implements Service.Response ... |
Ok, till this (hopefully) gets done, my workaround is to not generate the declarations and instead pointing the typings to source in my package.json: ...
"main": "dist/app/index.js",
"typings": "src/index",
... Because it's a private module, I'm publishing the source anyways, so it seems totally fine for now. |
the interface import * as Response from './Response';
export { Response };
declare module './Response' {
interface Response {
message: Response.Message;
}
}
export interface TypedResponse extends Response.Response {
type: string;
message: Response.Message;
} |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
Finally I had some time to continue my project and suddenly realized there is just no solution to my problem. So the conclusion of this: At this time (v. 2.5.2) it is just not possible (yet) to merge a module namespace with an interface of the same name. Even worse, the workaround with pointing to the source for the "typings" in package.json and stay with "declaration"-flag equals false (which worked fine with typescript 2.4.x) is not working anymore with v. 2.5.x. So there are mainly three possiblities:
import * as Service from './Service';
class MySuccessMessage implements Service.Response.Message ...
class MyResponse implements Service.Response.Response ... or to keep the hierarchical structure the way I initially thought of:
import * as service from './service';
class MySuccessMessage implements service.response.Message ...
class MyResponse implements service.Response ... which is acceptable.
import * as Service from './Service';
class MySuccessMessage implements Service.Response.Message ...
class MyResponse implements Service.IResponse ... but there is a good reason that naming conventions of typescript point out to omit the prefixes, because if you base on abstraction your "interfaces" are the main thing you handle with for e.g. types, castings and dependency injection. You really won't be cluttered with silly prefixes literally everywhere. |
TypeScript Version: 2.3.4 and nightly (2.4.0-dev.20170610)
Trying to build up a hierarchical namespace structure with modules.
All seems fine till setting --declaration flag to true.
Code
index.ts
Service.ts
Response.ts
Compiling with:
Expected behavior:
No errors while compiling and printing out:
just like it does without setting
--declaration
to true or by removing theextends Response
fromexport interface TypedResponse extends Response
.Actual behavior:
Getting error:
sample project with code from above:
export-error-test.zip
The text was updated successfully, but these errors were encountered: