Closed
Description
openedon 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};
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment