Skip to content

Produce #17640's anonymous type declarations from function types #17641

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

Closed
SamPruden opened this issue Aug 6, 2017 · 6 comments
Closed

Produce #17640's anonymous type declarations from function types #17641

SamPruden opened this issue Aug 6, 2017 · 6 comments
Labels
Duplicate An existing issue was already created

Comments

@SamPruden
Copy link

SamPruden commented Aug 6, 2017

This issue is branching out of discussion in #17636, and depends on #17636 and #17640.

Working together, these features aim to eliminate the need for #6606, by providing type switching and filtering within the type system, and making it possible to access the return types of functions.

Type declaration overloads provide all the power of function overloads.

declare function foo (num: number): {aNumber: number};
declare function foo <T> (other: T): {aDefault: T};

can be described by type declaration overloads as

type Foo <T extends number> = {aNumber: number};
type Foo <T> = {aDefault: T};

This proposal is for allowing the conversion of a function type into the equivalent anonymous overloaded type declaration.

interface Fizz {
    foo (num: number): {aNumber: number};
    foo <T> (other: T): {aDefault: T};
}

// Here we're getting the return type of foo by overload
type ANumber = (typeof Fizz["foo"])<number>;
type ADefault = (typeof Fizz["foo"])<string>;

where typeof Fizz["foo"] was expanded to

(
    type <U extends number> = {aNumber: number};
    type <U> = {aDefault: U};
)
@SamPruden
Copy link
Author

The title of this issue is a mess, any suggestions?

@SamPruden SamPruden changed the title Add support for keyof function types to produce anonymous type declarations Use keyof operator for function type -> anonymous type declaration conversion Aug 6, 2017
@KiaraGrouwstra
Copy link
Contributor

Might say 'type functions from function types' following Idris's nomenclature of 'type function' referring to types with generics (takes types, returns a type), but yeah haven't heard that here as much.

@SamPruden SamPruden changed the title Use keyof operator for function type -> anonymous type declaration conversion Produce #17640's anonymous type declarations from function types Aug 7, 2017
@SamPruden
Copy link
Author

type functions from function types

That seems pretty confusing to me, given that I'm a filthy casual who's never even read a line of Idris. I've tried something else, not sure if I've actually improved things though.

@KiaraGrouwstra
Copy link
Contributor

Yeah, mine sounded pretty rather than clear. Yours sounds clearer.

Idris

It's barely used afaik, but made some headlines in the Haskell community for doing some things better.

@mhegazy
Copy link
Contributor

mhegazy commented Aug 23, 2017

Looks like this should be in #17640 instead. i am not also convinced that even with #17640, this is possible for the general case. either ways, let's keep the discussion in #17640.

@mhegazy mhegazy added the Duplicate An existing issue was already created label Aug 23, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Sep 6, 2017

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@mhegazy mhegazy closed this as completed Sep 6, 2017
@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