Microsoft/TypeScript
Instantiable types from return types of contextual signatures don't provide contextual type information for return expressions
Offen
#61.197 geöffnet am 16.02.2025
Domain: check: Contextual TypesHelp WantedPossible Improvement
Repository-Metriken
- Stars
- (108.860 Sterne)
- PR-Merge-Metriken
- (PR-Metriken ausstehend)
Beschreibung
🔎 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