Can't find namespace when using re-exported class in generics

First of all, I was not sure what title I should give to this question. If anyone understands better, feel free to edit it.

I have a folder models

in which I have a set of model classes:

export default class Dog {
    id: string;
}

export default class Cat {
    id: string;
}

      

In the same folder, I also have a file index.ts

that exports them like this:

import Cat from './Cat';
import Dog from './Dog';

export default {Cat, Dog};

      

The idea is that elsewhere in my application, I have to import all models at the same time, rather than import them separately:

import models from '../models';

      

This works as expected - I can create new instances like this:

let dog = new models.Dog();

      

Unfortunately it doesn't work when I try to use it as a generic argument like this:

class Foo extends Bar<models.Cat> {
}

      

When I try to do this, I get the following error: TS2503:Cannot find namespace 'models'

.

Is there a way to make this work for general parameters?

+3


source to share





All Articles