Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

TypeScriptError: Class 'x' used before its declaration.

Discussion in 'Project Tiny' started by MUGIK, Dec 7, 2018.

  1. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    I found this problem very nasty, that's why I wrote that post.

    If you see compilation error in console TypeScriptError: Class 'X' used before its declaration. then you need to rename file, that contains class 'X', to something like 'aX.ts'. So the idea is to make this file compile before any other(alphabetization).

    https://github.com/Microsoft/TypeScript/issues/17742
     
    romiohasan likes this.
  2. etienne_unity

    etienne_unity

    Unity Technologies

    Joined:
    Aug 31, 2017
    Posts:
    102
    Also, as a comment in the GitHub issue suggests, you can add a reference comment at the top of your file to guide the compiler:
    /// <reference path="IncludeThisFirst.ts"/>
     
    romiohasan and scastner like this.
  3. romiohasan

    romiohasan

    Joined:
    Apr 8, 2019
    Posts:
    13
    thanks a lot for the post. saved a lot of time