Skip to content

Not again: A class must be declared after its base class. #14806

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

Closed
pankleks opened this issue Mar 22, 2017 · 23 comments
Closed

Not again: A class must be declared after its base class. #14806

pankleks opened this issue Mar 22, 2017 · 23 comments
Labels
Bug A bug in TypeScript

Comments

@pankleks
Copy link

Hello,

I just upgraded 2.1.5 to 2.2.2 and get lots of this errors (was all fine on 2.1.5).
For your information I'm not using modules - generating all into single JS file.

@benjamingr
Copy link

Can you share an isolated snippet of code that causes this issue and broke between 2.1.5 and 2.2.2?

@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Mar 23, 2017
@pankleks
Copy link
Author

pankleks commented Mar 23, 2017

Hello,

It will be hard as solution has over 300 files. I think this functionality had some issues from the very beginning. I was never able to figure it out.
Since beginning I had situations where it just worked, and situations where I had to manually add /// <reference ... - I could not tell why it worked for some and not for the others.

With different releases of TS I could remove some references or had to add some - meaning this was not stable.
But with 2.2.2 release I have over 100 errors like that.

I observed 2 additional strange things with 2.2.2:

  1. Even if I add <references to and rich moment where TSC is saying all is ok, I got failure at run-time saying some method is undefined
  2. I'm using VSCode - when I compile with TSC I see these errors -> which are displayed in VS errors list, when I click on error (ts file is opened) and error disappears from the list. This suggests that VS build in TSC does not pick it as an error - super strange.

In tsconfig I'm using outFile and not listing all ts files explicitly but using include with *.ts.
Can you explain how it works in case outFile is used?
I'm quite sure if I would put all of my classes in single file it would work - so I don't know why TSC is not able to figure out proper order of including files.

I don't know if many people uses outFile instead of modules, but I still think this is very desired option especially for web dev.

Let me know how I can help ...

@mhegazy
Copy link
Contributor

mhegazy commented Mar 23, 2017

@pankleks can you share a repro, we would love to investigate more and fix the underlying issue.

@pankleks
Copy link
Author

@mhegazy it's not code I can share publicly - only on priv.

@mhegazy
Copy link
Contributor

mhegazy commented Mar 23, 2017

can you reproduce the issue on a sample project, if you distill it down to two/three files that are showing the symptoms, we would only be interested in class heritage clauses, and triple-slash references not the rest of the file.

@pankleks
Copy link
Author

Planck.zip

Hello,

Please find solution strip from most of the code.
Some of the errors disappeared but there are still some. Hope it will be enough to investigate.

Compiles OK with 2.1.5, fails with 2.2.2

@RyanCavanaugh
Copy link
Member

I can't repro this with 2.2.2

@RyanCavanaugh
Copy link
Member

What file ordering mechanism does this project use? I don't see any reference directives or explicit file list - it's likely TS is just picking up these files in the order they appear on disk, which isn't even stable machine-to-machine

@pankleks
Copy link
Author

hmm, this is what I have:
image

I'm not using npm - using official installer release from MS.

@pankleks
Copy link
Author

pankleks commented Mar 28, 2017

@RyanCavanaugh just use:

    "incluide": [        
        "Planck.Core/*.ts",
        "Planck.UI/*.ts"
    ]

@RyanCavanaugh
Copy link
Member

What's the output of tsc --listFiles ?

@pankleks
Copy link
Author

@RyanCavanaugh
That's exactly my point - why should I use reference? They are all compiled to single file, TS should be able to figure out dependencies.

If I put all classes in single TS file it's compiling fine.

And at last, why it's working in 2.1.5 and not in 2.2.2?

@pankleks
Copy link
Author

pankleks commented Mar 28, 2017

listFiles.txt

Looking at the output - it's not honoring order of include in tsconfig.json - not sure if it was ever implemented, but maybe it should.

@RyanCavanaugh
Copy link
Member

It's always been the case that tsc does not figure out an ordering of your input files (see #1359 and similar threads). I can't figure out how this code ever ran without error -- certainly any class defined in a file alphabetically before Component should have failed.

Can you confirm that tsc --listFiles in 2.1.5 produces a different order?

@pankleks
Copy link
Author

listFiles.215.txt

Looks like 2.1.5 order is following one specified in include.

@pankleks
Copy link
Author

pankleks commented Mar 28, 2017

so here are my thoughts:

  1. tsc (both 2.1.5 and 2.2.2) are able to find proper order if all classes are in single TS file. I really don't understand why (in case modules are not used and output is generated to single file) tsc could not load all the files and then compile
  2. I think tsc should respect include order - it's IMO very logical assumption
  3. In the end - it looks there is some instability in tsc anyway - as order of files (for same solution) is different between 2.1.5 and 2.2.2

Using /// <reference is really nightmare when you have large solutions (my has over 300 files).
If you think point 1 is too specific/hard to implement (which I can understand), I believe point 2 should be very simple and gives you means to solve such errors without referencing.

Today, I really don't know when to reference or not - as it's not stable.

Thanks for help!

@pankleks
Copy link
Author

pankleks commented Mar 31, 2017

Hello, any update on this?

I really think solution 2 is the way to go here, and it should be easy to implement.
In the end - it looks today that include order is not deterministic anyway.

Thanks!

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript and removed Needs More Info The issue still hasn't been fully clarified labels Mar 31, 2017
@RyanCavanaugh
Copy link
Member

Bug. While the order from any given include directive's globbing is not deterministic, each set of include results should appear in the same order as the directives

@pankleks
Copy link
Author

Awesome - thank you so much!

@pankleks
Copy link
Author

Hello, any update when this might be implemented? If you point me to code maybe I can try to help.

@mhegazy mhegazy assigned ghost Apr 17, 2017
@mhegazy mhegazy added this to the TypeScript 2.4 milestone Apr 17, 2017
@ghost
Copy link

ghost commented May 8, 2017

!
The tsconfig.json uses "incluide" instead of "include", so the default include is used instead, which gives you undefined ordering.

@mhegazy mhegazy closed this as completed May 8, 2017
@pankleks
Copy link
Author

pankleks commented May 8, 2017

Guys, I used "include" and have same result.

@ghost
Copy link

ghost commented May 8, 2017

It's working for me on the Planck.zip sample you uploaded (testing with [email protected]); when I change "incluide" to "include", the output of --listFiles matches the order of the "include" array.

@microsoft microsoft locked and limited conversation to collaborators Jun 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants