-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Mapped type index access does not work well with Extract utility type #50103
Comments
From TypeScript's perspective, const getIt = <T extends Both>(b1: T, b2: T) => {
mapper[b1.type](b2);
}
getIt<Both>({ type: Type.A, x: 0 }, { type: Type.B, y: "" }); 4.7 added support for |
@RyanCavanaugh Is there no way to make it work with a single parameter? as it is now it requires me to use getIt2<Type>(Type.A, {type: Type.B, y: '4'});
getIt2(Type.B, {type: Type.A, x: 5}); On the other hand |
Using multiple parameters isn't required to induce unsoundness. You could take |
Which is exactly the case for |
#47109 outlines the decision of which sorts of signatures/usages get this treatment and which don't. |
@RyanCavanaugh so back to the original question then - is there any way to pass a single parameter and make the types work? Maybe without extract? I am kind of lost how to tackle it |
@RyanCavanaugh After revisiting this issue I think the main issue is: type GetByType<T extends Type> = Extract<Both, {type: T}>;
const a = <T extends Type>(value: GetByType<T>) => value.type; I expect that |
Bug Report
π Search Terms
indexed access types
π Version & Regression Information
Not a regression
β― Playground Link
link
π» Code
π Actual behavior
getIt
andgetIt3
doesn't compile although somehowgetIt2
compiles.π Expected behavior
All three examples should compile or at least
getIt3
The text was updated successfully, but these errors were encountered: