-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
type transformation for mapping object properties to function parameters #12265
Comments
I can see this, paired with substraction types, being used for
|
This is really interesting |
What determines the order of the parameters? // somefile.ts
interface Data {
otherProperty: string;
}
// otherfile.ts
interface Data {
name: string;
value: number;
}
// mainfile.ts
type Constructor<T> = (P in T) => T;
type CreateData = Constructor<Data>; // ? |
the order of declaration:
|
in you case it should be a type error since the order cannot be determined |
Why not just make object spread types valid in argument positions (so the spread type flattens into part of the argument list)? I think that would solve this elegantly: type Constructor<T> = (...T) => T;
interface Data {
name: string;
value: number;
}
type CreateData = Constructor<Data>; It also makes it obvious how to combine a spread object with normal arguments, and removes a confusingly useless type parameter. |
because using
|
I don't know why we didn't decline this earlier. We can't take a reliance on property ordering. |
now that we have map types it would nice being able to map properties to function parameters
would desugar to
The text was updated successfully, but these errors were encountered: