Microsoft/TypeScript

Non-exported recursive type alias is inlined until it falls back to any in declarations

Open

#58,696 创建于 2024年5月29日

在 GitHub 查看
 (3 评论) (0 反应) (0 负责人)TypeScript (6,726 fork)batch import
BugDomain: Declaration EmitHelp Wanted

仓库指标

Star
 (48,455 star)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 9 个 PR)

描述

🔎 Search Terms

declarations recursive types

🕗 Version & Regression Information

  • This is the behavior in every version I tried (before 4.4 it was either a stack overflow crash or an error on the recursive type)

⏯ Playground Link

Playground Link

💻 Code

// @declaration: true
// @filename: utils.ts 

type Recursive<T>  =  T extends Array<infer V>? Recursive<V>: T;

export const f = <T>(): Recursive<T> => { return null! } 

// @filename: index.ts 
import { f } from './utils';
export const a = f;

🙁 Actual behavior

In declarations, the type for a is printed as a: () => T extends (infer V)[] ? V extends (infer V)[] ? V extends (infer V)[] ? V extends (infer V)[] ? V extends (infer V)[] ? V extends (infer V)[] ? V extends (infer V)[] ? V extends (infer V)[] ? V extends (infer V)[] ? V extends (infer V)[] ? V extends (infer V)[] ? any : V : V : V : V : V : V : V : V : V : V : T;

🙂 Expected behavior

Recursive can't be represented without falling back to any (as seen above) so it should just be an error instead of silently to any

Additional information about the issue

Related to #55832

贡献者指南