Skip to content
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

Class 'x' used before its declaration #17742

Closed
arashebrahimi opened this issue Aug 11, 2017 · 4 comments
Closed

Class 'x' used before its declaration #17742

arashebrahimi opened this issue Aug 11, 2017 · 4 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@arashebrahimi
Copy link

arashebrahimi commented Aug 11, 2017

##

TypeScript Version: 2.4.1
Visual Studio Version: 14.0.25420.01 Update 3

File: ParallelogramF.ts
namespace JMath { export class ParallelogramF extends Polygon { ... } }
File: Polygon.ts
namespace JMath { export class Polygon { } }

Expected behavior:
Class Polygon must be known correctly.

Actual behavior:
Error Occurs: Class Polygon used before its declaration.

This occurs only when 'Combine JavaScript output into file' checkbox in project properties is checked and some 'xxx.js' file name is specified in front of it.

Solution:
1- When I change the name of file "ParallelogramF.ts" to "ZParallelogramF.ts" problem solves and it compiles correctly!!!!
2- When I uncheck 'Combine JavaScript output into file' checkbox it compiles correctly!!!!

Changing place of 'TypeScriptCompile Include="ParallelogramF.ts"' in ".csproj" file of the project to the last item inside its parent tag does not help.

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Aug 17, 2017
@RyanCavanaugh
Copy link
Member

You will note that in the cases where you get an error, the compiled code will not run.

@arashebrahimi
Copy link
Author

Thank you for response,

I can not find the relation between this issue and your response?!!!
It is obvious that when there is an error, the compiled code will not run!!!!!!!!!

But I talked about incorrect 'error' when I compile!!!!
Where I talked about 'run'???

I said there is a bug when I compile, It should be compiled without error, but I get 'incorrect' error!!!!

@grahamwager
Copy link

@arashebrahimi Try adding
/// <reference path="Polygon.ts"/>
to the very top of your ParallelogramF.ts file

There may be a "newer" way of doing that, but that let's the compiler know to compile Polygon.ts before ParallelogramF.ts when compiling into a single file

@ghost
Copy link

ghost commented Dec 19, 2017

I don't understand how this is expected behavior. The issue is that the child class isn't being recognized as such within the same namespace -- which should, in theory, eliminate the need to explicitly call out the reference. The compiler should know to compile the base class prior to any and all child classes.

What I believe @arashebrahimi is stating is that it appears to be an alphabetization issue where child classes that come after the base class (in file name) alphabetically recognize the inheritance relationship, but those that come prior don't. I've found that this issue doesn't exist for interfaces, however.

I'm able to reproduce this issue with TS 2.5.3 in Visual Studio Version 15.4.5.

@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
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants