Microsoft/TypeScript
在 GitHub 查看`silentNeverType` leak in contextual parameter types coming from anonymous non-aliased object type instantiations
Open
#62,345 创建于 2025年8月27日
BugDomain: check: Type InferenceHelp Wanted
仓库指标
- Star
- (48,455 star)
- PR 合并指标
- (平均合并 6天 17小时) (30 天内合并 9 个 PR)
描述
🔎 Search Terms
silent never type return type inference alias propagating anonymous object
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
interface P<T> {
then: (onfulfilled: (value: T) => unknown) => unknown;
}
interface PConstructor {
new <T>(executor: (resolve: (value: T) => void) => void): P<T>;
}
declare var P: PConstructor;
declare function foo1<T>(x: () => P<{ default: T }>): T;
const result1 = foo1(() => {
return new P((resolve) => {
resolve;
});
});
type WithDefault<T> = { default: T };
declare function foo2<T>(x: () => P<WithDefault<T>>): T;
const result2 = foo2(() => {
return new P((resolve) => {
resolve;
});
});
declare function foo3<T>(x: () => P<[T]>): T;
const result3 = foo3(() => {
return new P((resolve) => {
resolve;
});
});
declare function foo4<T>(x: () => P<{ default: { prop: T } }>): T;
const result4 = foo4(() => {
return new P((resolve) => {
resolve;
});
});
declare function foo5<T>(x: () => P<{ default: [T] }>): T;
const result5 = foo5(() => {
return new P((resolve) => {
resolve;
});
});
🙁 Actual behavior
Only foo2 and foo3 have errors and we can see that their inner resolves reference never
🙂 Expected behavior
All of those should consistently error and resolve should be typed as (value: unknown) => void. Specifically, foo1 and foo2 are the almost the same signatures but foo2 is using a type alias in its declaration which changes the inference behavior. This is strong indication of the bug here
Additional information about the issue
No response