Reputation: 673
Let's say we have a plain javascript constructor function that has a static property called extend
. If we pass a string into this method (extend
) it will create a new constructor function on the window object.
Here is a implementation of that: https://canjs.com/docs/can.Construct.extend.html
Here is my type definition:
declare module "can/construct/" {
interface ConstructFactory {
new(): Construct;
}
class Construct {
constructor();
static extend(name: string): ConstructFactory;
static extend(name: string, staticProperties: {}): ConstructFactory;
static extend(name: string, staticProperties: {}, instanceProperties: {}): ConstructFactory;
static extend(staticProperties: {}, instanceProperties: {}): ConstructFactory;
static extend(instanceProperties: {}): ConstructFactory;
}
}
My typescript file looks like:
import {Construct} from "can/construct/";
Construct.extend('Foo');
let foobar = new Foo();
But i get an error:
TS2304: Cannot find name 'Foo'.
How can I let typescript know that Foo
is created in the extend
method?
Upvotes: 0
Views: 121
Reputation: 276303
how can i letting typescript know that Foo is created in the extend method
You cannot declare a function that when called pollutes the global namespace. That feels like a bad idea and so I doubt it will ever be supported by TypeScript.
Note: you can declare a function that will return a constructor variable for you. But this is not the question you are asking.
Upvotes: 2