-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
Domain: check: Contextual TypesThe issue relates to contextual typesThe issue relates to contextual typesHelp WantedYou can do thisYou can do thisPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some casesThe current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone
Description
π Search Terms
instantiable contextual signature return types
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
π» Code
type ContextStates =
| {
status: "loading";
data: null;
}
| {
status: "success";
data: string;
};
declare function createStore<TContext>(
context: TContext,
config: {
on: Record<string, (ctx: TContext) => TContext>;
},
): void;
const store = createStore(
{
status: "loading",
data: null,
} as ContextStates,
{
on: {
fetch: () => ({
status: "success",
data: "hello",
}),
},
},
);π Actual behavior
status: "success", errors
π Expected behavior
no error
Additional information about the issue
Making (ctx: TContext) => TContext into a type parameter makes it work (see TS playground) but that's not natural to write and isn't broadly applicable as a workaround
Metadata
Metadata
Assignees
Labels
Domain: check: Contextual TypesThe issue relates to contextual typesThe issue relates to contextual typesHelp WantedYou can do thisYou can do thisPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some casesThe current behavior isn't wrong, but it's possible to see that it might be better in some cases