-
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
Error when trying to emit declarations for a module with a non exported base class #9865
Comments
Generating a declaration file requires some additional restricts, e.g. that the types used in an exported declaration have the same visibility. these errors are not reported if you do not care about declaration files. in this sample you need to export your abstract class as well. |
I can understand the restriction you mention although it means we always have to export a whole type hierarchy, from top to bottom. But why not. However, what is quite disturbing, is when such a definition file above, animal.d.ts (without From my point of view, this restriction when emitting should be removed, since it compiles (emission and consumption), or |
emitting declarations adds additional restrictions that are not needed if you are not emitting declarations.
the rational here is in a .d.ts file all declarations are exported by default regardless of the declare abstract class Animal {
....
}
export declare class Snail extends Animal {
....
} really exports two classes, so the error, in a sense, tells you this is going to happen. you can then decide if this is what you really intend, or you want change the public shape of |
Ok, I resign ^^. Good to know --declaration flag adds addition checks. I may use it for pedantic compilation. |
One thing to note, the errors you get from declaration emit are only "visibility" errors. so no new type relationship constraints, or syntax checks. it is just something of two forms:
|
Maybe the compiler could be nice to generate the corresponding .d.ts file although complaining :p |
that is possible. the reason here is, some other part of your system might be using the declaration file to build against or get intellisense, and overriding an existing declaration file with one that is known to have errors did not seem like the right experience. |
TypeScript Version: 2.0.0
Code
I'm trying to emit declarations files .d.ts with
tsc --declaration
in order to get such a following file:Expected behavior:
File animal.js well generated as well as file animal.d.ts:
Actual behavior:
File animal.js well generated but no file animal.d.ts. I got an error instead:
error TS4020: Extends clause of exported class 'Snail' has or is using private name 'Animal'.
It is maybe a misunderstanding of mine, but in my mind, when a code compiles with tsc, it should also compile with the
--declaration
flag.For information, here is my tsconfig.json:
The text was updated successfully, but these errors were encountered: