mode777 mode777 - 1 year ago 101
TypeScript Question

Typescript: Type of exported AMD class not found

Im using Typescript with a requirejs setup, so typescript is configured to use AMD modules.

I'm trying to export a class and use it from another one. Here is some example code.

//file: ClassA.ts
export = class ClassA {

//file: ClassB.ts
import ClassA = require("ClassA")

export = class ClassB {
constructor(classA: ClassA) { //ClassA is not found
// However this will work:
let c = new ClassA();

When compiling I get the following error.

ClassB.ts(4,25): error TS2304: Cannot find name 'ClassA'.

However intellisense is fine with the instanciation of ClassA and I get full intellisense for the instance.

So what am I doing wrong here?

EDIT: Here is my tsconfig.json

"compileOnSave": true,
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es5",
"module": "amd"
"exclude": [

Answer Source

It looks like you are mixing JavaScript and TypeScript syntax for exporting and importing classes.
Try this syntax:

export class ClassA {
    print() {

import {ClassA} from './ClassA';

class ClassB {
    print() {
        let a = new ClassA();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download