-
-
Notifications
You must be signed in to change notification settings - Fork 529
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
ReferenceError: MyClass is not defined #52
Comments
This is still Node, you need to import or require that file somehow. References in TypeScript are used to tell the compiler this file exists in the current context, but in your case it does not. Try doing: export class MyClass {
x: number;
y: number;
constructor(x: number, y :number) {
this.x = x;
this.y = y;
}
} And import { MyClass } from './MyClass'
var myClass = new MyClass(2,3);
console.log(myClass.x, myClass.y); |
This of course works, much appreciated. As to expand on my understanding, are you able to explain why in my case the reference doesn't tell the compiler the file exists? Is there an expectation of tsconfig.json here? |
@staff0rd It tells the TypeScript compiler this file exists within scope fine, that works. The error your getting is from node. Just because the TypeScript compiler believes you when you said it was in scope, it doesn't mean it actually is during runtime. Personally, I avoid references since I'm usually developing for CommonJS output. If you want to develop global browser modules, that's where you might use references with TypeScript (or, for global polyfills and |
I have the following files;
MyClass.ts
MyScript.ts
Compiling via
tsc
is successful, however I cannot executeMyScript.cs
withts-node
. Am I doing something wrong?Repro
The text was updated successfully, but these errors were encountered: