Currently, I am in the process of migrating a decently sized project from JavaScript to TypeScript. My strategy involves renaming the .js
files to .ts
files, starting with smaller examples before tackling the larger codebase. The existing JavaScript code is structured like classes, and for simplicity, I decided to begin by converting a simple class called Token
that has no external dependencies. Below is a simplified version of the class where an error occurs during compilation using tsc 1.8, displaying the message "Property 'INVALID_TYPE' does not exist on type () => any."
function Token() {
this.source = null;
this.type = null; // token type of the token
this.line = null; // line=1..n of the 1st character
this.column = null; // beginning of the line at which it occurs, 0..n-1
return this;
}
Token.INVALID_TYPE = 0;
I have read about how I can transform the function Token
declaration into a class Token
to resolve the issue by making INVALID_TYPE
a static member of the Token
class. However, with close to 10k lines of code, this approach might be quite intricate. I am exploring simpler solutions to address these errors incrementally. One potential workaround suggested is to modify the last line as follows:
(<any>Token).INVALID_TYPE = 0;
Are there any better quick-fixes available to temporarily address this specific TypeScript error?