Skip to content
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

Define types when assigning constructor functions using const #18967

Closed
aaronlahey opened this issue Oct 5, 2017 · 2 comments
Closed

Define types when assigning constructor functions using const #18967

aaronlahey opened this issue Oct 5, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@aaronlahey
Copy link

aaronlahey commented Oct 5, 2017

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;
}
@aaronlahey aaronlahey reopened this Oct 5, 2017
@jcalz
Copy link
Contributor

jcalz commented Oct 5, 2017

This is a duplicate of #18942

@mhegazy mhegazy added the Duplicate An existing issue was already created label Oct 5, 2017
@aaronlahey
Copy link
Author

It looks like the issue this is a duplicate of was declined and closed. Closing this one as well.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants