Skip to content

Declaration emit errors (TS5088) on anonymous cyclic types that 6.0 elided to any #64656

Description

🔎 Search Terms

TS5088, cyclic structure, trivially serialized, declaration emit, elided any, TS 7

🕗 Version & Regression Information

Errors on 7.1.0-dev.20261006.1. 6.0.3 emits /*elided*/ any at the cycle instead. (7.0.2 also emitted /*elided*/ any for both repros below when I tried it, in case that helps narrow anything down.)

⏯ Playground Link

No response

💻 Code

// tsc --declaration --emitDeclarationOnly --strict repro.ts
type show<t> = { [k in keyof t]: t[k] } & unknown
type resolve<$, k extends keyof $> = show<{
	[p in keyof $[k]]: $[k][p] extends "ref" ? resolve<$, k> : $[k][p]
}>
declare const mod: <$>() => { [k in keyof $]: resolve<$, k> }
export const n = mod<{ Node: { value: number; next: "ref" } }>()

🙁 Actual behavior

error TS5088: The inferred type of 'n' references a type with a cyclic structure which cannot be trivially serialized. A type annotation is necessary.

🙂 Expected behavior

Same as 6.0.3, which emits:

export declare const n: {
    Node: {
        value: number;
        next: /*elided*/ any;
    };
};

Not sure whether the error is intended though! I can see the argument that an error is more honest than quietly writing any into a .d.ts, so if this is intentional, totally fair, but it might be worth calling out as a breaking change.

Additional information about the issue

Ran into this while moving ArkType's repo to TS 7. Here's what it looks like for an ArkType user exporting a scope with a recursive type:

import { scope } from "arktype"

const $ = scope({
	Node: { value: "number", "next?": "Node" },
	List: { head: "Node" }
})

// 6.0.3: emits, with `next?: /*elided*/ any` at the cycle
// 7.1.0-dev.20261006.1: error TS5088
export const types = $.export()

There's no reasonable annotation for users to write here, since the whole point is that the type is inferred from the definitions, so in practice this is a breaking change for anyone shipping declarations from code like this.

Thanks!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Needs InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions