Open
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