Closed
Description
Is there any way currently (or any desire to implement a way) to automatically create a type when the return value of a function includes { new }
and is assigned to a const
?
Code
Desired Syntax
class Struct<T extends object> {
public static define<T extends object>(): { new(t: T): Struct<T> } {
return Struct;
}
}
const Point = Struct.define<{
x: number,
y: number
}>();
// [ts] Cannot find name 'Point'.
function identity(p: Point): Point {
return p;
}
Current Syntax
class Struct<T extends object> {
public static define<T extends object>(): { new(t: T): Struct<T> } {
return Struct;
}
}
type PointData = { x: number, y: number };
type Point = Struct<PointData>;
const Point = Struct.define<PointData>();
function identity(p: Point): Point {
return p;
}