You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Error when trying to emit declarations for a module with a non exported base class #9865
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.
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.
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 export on the base class), is consumed by TypeScript, it compiles perfectly well. No error nor warning.
From my point of view, this restriction when emitting should be removed, since it compiles (emission and consumption), or tscwithout--declaration flag should report an error as well (when emitting and consuming).
However, what is quite disturbing, is when such a definition file above, animal.d.ts (without export on the base class), is consumed by TypeScript, it compiles perfectly well. No error nor warning.
emitting declarations adds additional restrictions that are not needed if you are not emitting declarations.
From my point of view, this restriction when emitting should be removed,
the rational here is in a .d.ts file all declarations are exported by default regardless of the export keyword. so
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 Snail to be what you expect.
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:
"A uses B, and B is not exported"
"A" is used but the compiler could not write its name (either shadowed by something with the same name, or comes from a different module that was not imported)
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.
Activity
mhegazy commentedon Jul 21, 2016
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.
yahiko00 commentedon Jul 22, 2016
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
exporton the base class), is consumed by TypeScript, it compiles perfectly well. No error nor warning.From my point of view, this restriction when emitting should be removed, since it compiles (emission and consumption), or
tscwithout--declarationflag should report an error as well (when emitting and consuming).mhegazy commentedon Jul 22, 2016
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
exportkeyword. soreally exports two classes,
AnimalandSnail.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
Snailto be what you expect.yahiko00 commentedon Jul 22, 2016
Ok, I resign ^^. Good to know --declaration flag adds addition checks. I may use it for pedantic compilation.
mhegazy commentedon Jul 22, 2016
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:
AusesB, andBis not exported"yahiko00 commentedon Jul 22, 2016
Maybe the compiler could be nice to generate the corresponding .d.ts file although complaining :p
mhegazy commentedon Jul 23, 2016
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.