Skip to content

Commit 3337425

Browse files
fix(adr-0087): a type literal in an interface or class header leaves its body a type body (#38179)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DDypKu7B9nwbu5WuV7AEio8)_ Fixes #38144 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:用户无感;只影响发版检查工具对「类型收窄」声明的判读,接口或类的声明头里带花括号类型时,成员的类型标注现在能被正确读到。 - 为什么做:属于发版破坏性变更登记检查的收尾工作,替审改动的人堵住一个偏宽的漏判。 - 出错会怎样:最坏情况是检查工具对少数声明误判,表现为某条变更说明被错误拦下或放行;只改检查脚本,可直接撤回。 - 要你做的:无。 ## What changes `scripts/check-adr-0087-registration.mjs`, one file, script only (publishes nothing, `skip-changeset`). - **The fix.** `braceOpensTypeBody` read its header back only to the previous `;`, `{` or `}`. In `export interface SortableFavoriteRowsProps<T extends { id: string }> {` that stops inside the constraint's braces, the header reads as `>`, the body is not classified as a type body, and `sitsInTypePosition` falls back to the value reading, so an annotated `renderRow: (item: T, drag: FavoriteRowDragProps) => React.ReactNode;` read as "carries NO return annotation" (erased; the permissive direction for predicate 4). The header is now read by a new `braceHeader`, which steps over and blanks a balanced brace group only when both conditions hold: (1) its opening brace follows a type-literal position (less-than, comma, open paren, pipe, ampersand, a lone equals, or the word `extends`); and (2) it sits inside a less-than, open paren or open bracket that is still open after it, which `closesAnOpenerBefore` checks by finding the text between the group and the body brace closing an opener it never opened. Every type literal a declaration header carries meets (2): constraints and defaults (`<T extends { id: string }>`, `<T = {}>`), heritage type arguments (`Base<{ a: 1 }>`), mixin calls. A brace that closes a statement never does, so a type alias closed by a bare brace with no semicolon (the ThemeProvider shape) stays a statement boundary, and so does a prior `class A {}`. Blanking keeps a keyword inside a stepped-over group (`{ class: 1 }`) out of the header. - **Review fix (S1, round 1).** Condition (2) above is new on this head. At af759f4 the equals arm stepped across a statement boundary with no semicolon: in `ui/packages/app-shell/src/chrome/ThemeProvider.tsx` lines 13-21, `type ThemeProviderState = { ... }` is closed by a bare brace and followed by `const initialState: ThemeProviderState = {`, so that value literal got the alias's `type ... =` header and `setTheme: () => null` read as a function type returning `null`. The same step also attached the alias to the import before it, so the alias's own `setTheme: (theme: Theme) => void` read as unannotated. Conditional-type (`extends`) and union (`|`) aliases with no semicolon had the same leak. - **N1.** `containerBodiesFor`'s docstring names all four kinds (object literal, class, interface, type-literal alias) and the companion-object case. - **N2.** Predicate 4's HEAD-side refusal prose is reflowed: "is REPORTED rather than guessed at" no longer breaks early. - **N3.** The companion object (`interface X` plus an object literal `X = {`) is pinned as AMBIGUOUS (TSO-I17). **The real instance**, through the shipping reader (`readTypeSurfaceRef`) on `ui/packages/app-shell/src/layout/SortableFavoriteRows.tsx`, at `origin/main` 9dca109 vs this branch: ```text before SortableFavoriteRowsProps.renderRow {"shape":"`SortableFavoriteRowsProps.renderRow`, which carries NO return annotation","type":null,"erased":true} after SortableFavoriteRowsProps.renderRow {"shape":"the return annotation of `SortableFavoriteRowsProps.renderRow`","type":"React.ReactNode","erased":false} before SortableFavoriteRowsProps.onReorder {... "type":null,"erased":true} after SortableFavoriteRowsProps.onReorder {... "type":"void","erased":false} ``` **Both review instances**, before (af759f4) and after (this head), compared with origin/main 9dca109: ```text main 9dca109 af759f4 this head ThemeProvider.tsx bare setTheme (alias, line 15) void erased (NO) void ThemeProvider.tsx lines 13-21, value setTheme null (value) "null" (type) null (value) app-generator.ts emitted theme-provider text, alias void null void app-generator.ts emitted theme-provider text, value null (value) null null (value) app-generator.ts itself, bare setTheme not found not found not found ``` In `app-generator.ts` itself the shape is inside a template literal, which the reader masks, so the file has no `setTheme` definition. The rows above read the emitted text, which is what the reviewer's lifted functions saw. ## Tests New pins in the gate's own `--self-test`: - TSO-U38: interface whose type-parameter constraint is a type literal (the real instance's shape). - TSO-U39: a type literal in a type-parameter default and in interface heritage type arguments. - TSO-U40: a class whose constraint, `extends` and `implements` clauses all carry type literals. - TSO-U41, TSO-U42 (lit controls): a class body before an object literal still ends that literal's header; a stepped-over `{ class: 1 }` is blanked; an object literal whose own header carries a type argument stays a value. Green with and without the fix. - TSO-U43 (lit control, the ThemeProvider shape): an alias with no semicolon, then a typed `const` literal, read both as lines 13-21 alone and under the file's head. The literal's arrow stays a VALUE. - TSO-U44: in the same file, the alias member reads `void`. - TSO-U45: the same statement boundary behind a conditional type (`extends`) and a union (`|`) with no semicolon. - TSO-I17 (N3): the companion object is AMBIGUOUS, "opens 2 object literals and interface bodies". - TSO-I18: the dotted spelling `SortableRowsProps.renderRow` behind a header type literal resolves to `React.ReactNode`. - TSO-I19 / TSO-I20: end to end through `scan()`: a concrete base behind the header is refused by predicate 4 (narrowed-from-erased is FALSE); a truly erased base (`=> any`) is admitted. Battery floors raised to the measured counts: `TSO-U` 37 to 45, `TSO-I` 20 to 25. The #38093/#38137 pins (R8, R9, G2, TSO-R8, TSO-R9, TSO-G2, TSO-U31 to U37, the TSO-I battery) stay green. <details><summary>Self-test, final head 9e13d6d</summary> ```text node scripts/check-adr-0087-registration.mjs --self-test EXIT=0 ✓ check-adr-0087-registration --self-test: 867 assertions over real temp git repos (real scan()/assertInputs() path) ``` (854 assertions at origin/main 9dca109.) </details> <details><summary>Ablation (fix reverted on disk, braceHeader returning the old back-to-previous-brace header)</summary> ```text ✗ check-adr-0087-registration --self-test -- 6 failure(s) • TSO-U38 • TSO-U39 • TSO-U40 • TSO-I18 • TSO-I19 (message must match "predicate 4: narrowed-from-erased] is FALSE"; actual: "still UNANNOTATED") • TSO-I20 (expected GREEN; got "still UNANNOTATED" at HEAD) ``` TSO-U41, TSO-U42 (lit controls) and TSO-I17 stay green under the ablation, as designed. Restored with `git checkout HEAD -- scripts/check-adr-0087-registration.mjs`, `git status --porcelain` empty. </details> <details><summary>Ablation 2 (round 1): the closesAnOpenerBefore guard commented out at 9e13d6d</summary> ```text ✗ check-adr-0087-registration --self-test -- 3 failure(s) • TSO-U43 (the ThemeProvider lit control) • TSO-U44 • TSO-U45 ``` U38 to U42 and I17 to I20 stay green under this ablation, because the guard does not affect them. Restored with `git checkout HEAD -- scripts/check-adr-0087-registration.mjs`, `git status --porcelain` empty. </details> ## Acceptance notes - The end-to-end red under the ablation is the strict direction ("still UNANNOTATED at HEAD"), because both revs share the header. The permissive direction the card names (a concrete base read as erased while HEAD reads annotated) is what TSO-U38 to U40 and TSO-I18 pin at the reader. - Header positions not stepped over: a type literal after a colon at header depth 0 does not arise in an interface or class header; an object-literal argument in a class `extends` expression (`extends mixin({ ... })`) sits behind an open paren and is stepped over. ## Verification Read first: `braceHeader` and `closesAnOpenerBefore` (the risk hunk is the pair of conditions that decide whether a closing brace ends the header), then TSO-U41 to U45. Two-minute check: `node scripts/check-adr-0087-registration.mjs --self-test` prints `867 assertions`. <details><summary>Local gate subset at 9e13d6d (dispatch-gates --commands, 34 families; --ran: 34 derived, 34 run, 0 NOT-MEASURED, a derived zero)</summary> All 34 commands, including `pnpm check:pm-dispatch-gates`, ran one after another, each exit code captured before any pipe, and every one exited 0. Highlights: `check-adr-0087-registration --base origin/main` exit 0; `--self-test` exit 0, 867 assertions; `check:nul-bytes` exit 0; `check:entry-guard` exit 0; `check:scripts-symbol-anchors` exit 0. `overlap-check` VERDICT clean: merges cleanly into origin/main 4f7aa88. Every other family CI runs is read from this PR's check-runs, not re-run locally. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_016WV4cxRDKprCtjpEdtiPFW)_ <!-- signed: repo:objectstack#1 · os-elon-musk · session_016WV4cxRDKprCtjpEdtiPFW --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 65ad1b4 commit 3337425

1 file changed

Lines changed: 172 additions & 16 deletions

File tree

‎scripts/check-adr-0087-registration.mjs‎

Lines changed: 172 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,10 @@ const SELF_TEST_BATTERIES = Object.freeze({
492492
'The #13080 category: `type-surface-only`': 29,
493493
'TSO-6048: THE REGRESSION PIN -- the founding case must never admit': 8,
494494
'TSO-N: the predicate set is pinned BY NAME, never by count': 3,
495-
'TSO-U: unit pins on predicate 4\'s readers': 37,
495+
'TSO-U: unit pins on predicate 4\'s readers': 45,
496496
'TSO-D (#15627): a DOTTED member path resolves through the object-literal nesting': 27,
497497
'TSO-C (#17279): a DOTTED member path resolves through a CLASS body': 17,
498-
'TSO-I (#37445): a DOTTED member path resolves through an INTERFACE or type-literal alias body': 20,
498+
'TSO-I (#37445): a DOTTED member path resolves through an INTERFACE or type-literal alias body': 25,
499499
'The #22918 category: `runtime-export-retired`': 49,
500500
'REX-N: the predicate set is pinned BY NAME, never by count': 3,
501501
'REX-U: unit pins on the operand grammar and the FROM-side reader': 24,
@@ -3686,20 +3686,92 @@ function sitsInTypePosition(masked, pos) {
36863686
* annotations: an `interface` or `class` body, a `type` alias's (or a type
36873687
* parameter default's) object type, an object type inside a union or intersection
36883688
* or a type argument, or one that follows a `:` which itself sits in a type
3689-
* position. Read from the header since the previous `;` / `{` / `}`; a header with
3690-
* braces of its own (`class C implements I<{ a: 1 }>`) is not classified.
3689+
* position. Read from the header `braceHeader` returns, so a header that carries a
3690+
* type literal of its own (`interface P<T extends { id: string }>`,
3691+
* `class C extends Base<{ a: 1 }>`) is still an interface or class header.
36913692
*/
36923693
function braceOpensTypeBody(masked, open) {
3693-
let start = open - 1;
3694-
while (start >= 0 && !';{}'.includes(masked[start])) start--;
3695-
const header = masked.slice(start + 1, open).trim();
3694+
const header = braceHeader(masked, open);
36963695
if (/(?:^|[^\w$.])(?:interface|class)\b/.test(header)) return true;
36973696
if (/^(?:export\s+)?(?:declare\s+)?type\s+[\w$]/.test(header) && header.endsWith('=')) return true;
36983697
if (/(?:^|[^|&])[|&]$/.test(header) || header.endsWith('<')) return true;
36993698
if (header.endsWith(':')) return sitsInTypePosition(masked, open);
37003699
return false;
37013700
}
37023701

3702+
/**
3703+
* The header of the `{` at `open` in the masked text, trimmed: everything since the
3704+
* previous `;`, `{` or `}`, except that a balanced `{ … }` group whose `{` follows a
3705+
* type-literal position -- `<`, `,`, `(`, `|`, `&`, `=` or the word `extends` -- AND
3706+
* that sits inside an angle, paren or bracket still open after it
3707+
* (`closesAnOpenerBefore`) is stepped over and BLANKED. That group is a type literal
3708+
* inside the header (a type-parameter constraint or default, a type argument in
3709+
* heritage), not the end of the statement before it.
3710+
*
3711+
* ⚠️ Reading back only to the previous brace stops inside such a literal, so
3712+
* `interface P<T extends { id: string }> {` reads as the header `>`: the body is not
3713+
* classified, and an annotated `f: (...) => T` in it reads as UNANNOTATED -- a
3714+
* concrete surface called erased, which predicate 4 admits (the permissive
3715+
* direction). A `}` whose `{` follows anything else -- `)`, `=>`, a name, `>` --
3716+
* closes a statement or a block and still ends the header, so a prior `class A {}`
3717+
* never leaks its keyword into the next brace's header. Blanking keeps a keyword
3718+
* spelled INSIDE a stepped-over group (`{ class: 1 }`) out of the header too.
3719+
*/
3720+
function braceHeader(masked, open) {
3721+
let header = '';
3722+
let i = open - 1;
3723+
for (;;) {
3724+
let start = i;
3725+
while (start >= 0 && !';{}'.includes(masked[start])) start--;
3726+
header = masked.slice(start + 1, i + 1) + header;
3727+
if (start < 0 || masked[start] !== '}') break;
3728+
let depth = 0;
3729+
let groupOpen = -1;
3730+
for (let j = start; j >= 0; j--) {
3731+
if (masked[j] === '}') depth++;
3732+
else if (masked[j] === '{' && --depth === 0) { groupOpen = j; break; }
3733+
}
3734+
if (groupOpen < 0) break;
3735+
const before = masked.slice(0, groupOpen).trimEnd();
3736+
if (!/(?:[<,(|&]|(?<![=!<>])=|(?:^|[^\w$.])extends)$/.test(before)) break;
3737+
if (!closesAnOpenerBefore(masked, start + 1, open)) break;
3738+
header = ' '.repeat(start - groupOpen + 1) + header;
3739+
i = groupOpen - 1;
3740+
}
3741+
return header.trim();
3742+
}
3743+
3744+
/**
3745+
* Whether the masked text in `[from, to)` closes a `<`, `(` or `[` it never opened --
3746+
* that is, whether a brace group ending just before `from` sits INSIDE an angle,
3747+
* paren or bracket that is still open where the group ends. Brace groups in the span
3748+
* are skipped whole, and the `>` of an arrow is not a closer.
3749+
*
3750+
* ⚠️ This is what makes `braceHeader`'s step a header question and not a statement
3751+
* question. Every type literal a declaration header carries sits inside one: a
3752+
* constraint or default (`<T extends { id: string }>`, `<T = {}>`), a heritage type
3753+
* argument (`Base<{ a: 1 }>`), a mixin call (`extends mixin({ … })`). A `}` that
3754+
* closes a STATEMENT is followed by no such closer -- `type S = { … }` with no `;`,
3755+
* then `const initial: S = {` -- and stepping over it would hand the value literal
3756+
* the alias's `type S =` header, so its unannotated `f: () => null` would read as a
3757+
* function TYPE returning `null` (a value called concrete).
3758+
*/
3759+
function closesAnOpenerBefore(masked, from, to) {
3760+
let depth = 0;
3761+
let braces = 0;
3762+
for (let k = from; k < to; k++) {
3763+
const c = masked[k];
3764+
if (c === '{') braces++;
3765+
else if (c === '}') braces--;
3766+
else if (braces > 0) continue;
3767+
else if (c === '<' || c === '(' || c === '[') depth++;
3768+
else if (c === ')' || c === ']' || (c === '>' && masked[k - 1] !== '=')) {
3769+
if (--depth < 0) return true;
3770+
}
3771+
}
3772+
return false;
3773+
}
3774+
37033775
/**
37043776
* The return type of a function TYPE, read from just after its parameter list's
37053777
* `)` at `from`: the text after `=>`, to the member's end -- a `;` or `,` at depth
@@ -3809,12 +3881,14 @@ function classBodiesFor(structural, name, from, to) {
38093881

38103882
/**
38113883
* Every body a path segment named `name` can name inside `[from, to)`: an object
3812-
* literal or a class (#17279), in file order.
3813-
*
3814-
* ⚠️ The union is what makes the count meaningful. A segment naming BOTH an object
3815-
* literal and a class is AMBIGUOUS in exactly the way two object literals are, and
3816-
* counting the two kinds separately would let one of each through as "one of each
3817-
* kind" -- a silent pick, which is the "writable but wrong" reference the dotted
3884+
* literal, a class (#17279), an interface or a type-literal alias (#37445), in file
3885+
* order.
3886+
*
3887+
* ⚠️ The union is what makes the count meaningful. A segment naming bodies of two
3888+
* kinds -- an object literal and a class, or the companion object that an
3889+
* `interface X` plus an `X = {` literal makes -- is AMBIGUOUS in exactly the way two
3890+
* object literals are, and counting the kinds separately would let one of each
3891+
* through as "one of each kind" -- a silent pick, which is the "writable but wrong" reference the dotted
38183892
* spelling exists to avoid.
38193893
*
38203894
* @returns {{ open: number, close: number, kind: string }[]}
@@ -4583,9 +4657,9 @@ export function verifyTypeSurfaceOnly(refs, { base, head, cwd, bumps, packages,
45834657
` ${read.refusal}\n` +
45844658
' A dotted member path is walked through the nesting it names -- an object literal, a\n' +
45854659
' class body (#17279), or an interface or type-literal alias body (#37445) -- and a walk\n' +
4586-
' that lands on zero or on several candidates is\n' +
4587-
' REPORTED rather than guessed at -- a reference that resolves to the wrong same-named\n' +
4588-
' member reads as a true sentence about a member the diff never touched (#15627).\n' +
4660+
' that lands on zero or on several candidates is REPORTED rather than guessed at -- a\n' +
4661+
' reference that resolves to the wrong same-named member reads as a true sentence about\n' +
4662+
' a member the diff never touched (#15627).\n' +
45894663
HOW(null),
45904664
);
45914665
continue;
@@ -7931,6 +8005,44 @@ function selfTest() {
79318005
memberReturnAnnotation('export const o = { nested: { f: async (x) => x } };\n', 'f')?.annotation === null &&
79328006
memberReturnAnnotation('export interface A { nested: { f: (x: number) => Row } }\n', 'f')?.annotation === 'Row', 'TSO-U37: an `any` return stays readable as `any`, an `async` arrow is a value, and a type literal nested under a type keeps its type reading');
79338007

8008+
// U38-U42: a type literal in the HEADER of an interface or class -- a
8009+
// type-parameter constraint, a type argument in heritage -- still leaves the
8010+
// body a type body. `braceHeader` steps over that literal; before it the header
8011+
// read back stopped inside the literal's braces, the body went unclassified, and
8012+
// an annotated `f: (...) => T` read as UNANNOTATED (erased: the permissive
8013+
// direction for predicate 4). U41-U42 are the lit controls: a brace group that
8014+
// ends a statement still ends the header, and an object literal whose header
8015+
// carries a type literal is still a value.
8016+
assert(memberReturnAnnotation('export interface P<T extends { id: string }> {\n items: readonly T[];\n renderRow: (item: T, drag: DragProps) => React.ReactNode;\n}\n', 'renderRow')?.annotation === 'React.ReactNode', 'TSO-U38: an interface whose TYPE-PARAMETER CONSTRAINT is a type literal (`T extends { id: string }`) keeps its body a type body -- the function-typed property reads its return type');
8017+
assert(memberReturnAnnotation('export interface P<T = { a: 1 }> extends Base<{ b: 2 }>, Other<{ c: 3 } | null> {\n f: (x: T) => Row;\n}\n', 'f')?.annotation === 'Row', 'TSO-U39: a type literal in a type-parameter DEFAULT and in interface HERITAGE type arguments is stepped over -- the body is still the interface body');
8018+
assert(memberReturnAnnotation('export class C<T extends { id: string }> extends Base<{ a: 1 }> implements I<{ b: 2 }> {\n f: (id: string) => Promise<T>;\n}\n', 'f')?.annotation === 'Promise<T>', 'TSO-U40: a CLASS whose constraint, `extends` and `implements` clauses all carry type literals keeps its field annotation');
8019+
assert(memberReturnAnnotation('export class A { m() { return 1; } }\nexport const o = {\n f: (x: number) => x + 1,\n};\n', 'f')?.annotation === null &&
8020+
memberReturnAnnotation('const k = { class: 1 }\nexport const o = {\n f: (x: number) => x + 1,\n};\n', 'f')?.annotation === null, 'TSO-U41: LIT CONTROL -- a class BODY before an object literal still ends its header (its `{` follows a name, not a type-literal position), and a stepped-over `{ class: 1 }` is blanked, so neither leaks a `class` keyword into the literal\'s header: the arrow stays an unannotated VALUE');
8021+
assert(memberReturnAnnotation('export const o = call<{ a: 1 }>({\n f: (x: number) => x + 1,\n});\n', 'f')?.annotation === null, 'TSO-U42: LIT CONTROL -- an object literal whose own header carries a stepped-over type argument is still a VALUE, not a type body');
8022+
8023+
// U43-U45: a `}` that closes a STATEMENT is never stepped over, however the `{`
8024+
// before it was preceded. The shape is `ui/packages/app-shell/src/chrome/ThemeProvider.tsx`
8025+
// (and the theme-provider file `ui/packages/cli/src/utils/app-generator.ts` emits):
8026+
// a type alias with no `;`, then a typed `const` literal. Stepping over the alias
8027+
// body because its `{` follows `=` handed the literal the header `type S = … const
8028+
// initialState: S =`, so the VALUE `setTheme: () => null` read as a function TYPE
8029+
// returning `null`, and the alias's own members lost their header to the import
8030+
// before them. `closesAnOpenerBefore` is the rule: a header's type literal always
8031+
// sits inside a `<`, `(` or `[` still open after it.
8032+
{
8033+
const THEME_HEAD = 'import { createContext, useContext, useEffect, useState } from "react"\n\n' +
8034+
'type Theme = "dark" | "light" | "auto" | "system"\n\n' +
8035+
'type ThemeProviderProps = {\n children: React.ReactNode\n defaultTheme?: Theme\n storageKey?: string\n}\n\n';
8036+
const ALIAS = 'type ThemeProviderState = {\n theme: Theme\n setTheme: (theme: Theme) => void\n}\n\n';
8037+
const VALUE = 'const initialState: ThemeProviderState = {\n theme: "system",\n setTheme: () => null,\n}\n';
8038+
const aliasOnly = ALIAS.replace('setTheme: (theme: Theme) => void', 'other: string');
8039+
assert(memberReturnAnnotation(aliasOnly + VALUE, 'setTheme')?.annotation === null &&
8040+
memberReturnAnnotation(THEME_HEAD + aliasOnly + VALUE, 'setTheme')?.annotation === null, 'TSO-U43: LIT CONTROL, THE ThemeProvider SHAPE (its lines 13-21, and the whole head of the file) -- an alias closed by a bare `}` (no `;`), then a typed `const` object literal: the literal\'s arrow stays an unannotated VALUE, never a function type returning `null`');
8041+
assert(memberReturnAnnotation(THEME_HEAD + ALIAS + VALUE, 'setTheme')?.annotation === 'void', 'TSO-U44: ...and in the same file the ALIAS member reads its annotation (`void`) -- the alias body before it is a statement, not a header literal, so the import before it never becomes part of its header');
8042+
}
8043+
assert(memberReturnAnnotation('type C<T> = T extends { a: 1 } ? A : B\nconst o = {\n f: () => null,\n}\n', 'f')?.annotation === null &&
8044+
memberReturnAnnotation('type U = A | { a: 1 }\nconst o = {\n f: () => null,\n}\n', 'f')?.annotation === null, 'TSO-U45: the same statement boundary behind an `extends` (a conditional type) and a `|` (a union) with no `;` -- neither leaks its `type X =` header into the value literal after it');
8045+
79348046
// ---- TSO-D (#15627): a DOTTED member path, resolved through the nesting ---
79358047
//
79368048
// The grammar and the reader were widened in ONE commit, and this battery is
@@ -8521,6 +8633,50 @@ function selfTest() {
85218633
IFC_TYPES + '\nexport interface AuthClient {\n signOut(): Promise<void>;\n}\n'))),
85228634
[/cannot be resolved at HEAD/, /AMBIGUOUS/, /opens 2 interfaces/]);
85238635

8636+
// -- the companion object, and an interface whose HEADER carries a type literal --
8637+
{
8638+
const companion = 'export interface AuthClient {\n updateUser(): Promise<Ifc>;\n}\n' +
8639+
'export const AuthClient = {\n updateUser: async (): Promise<Obj> => ({} as Obj),\n};\n';
8640+
const r = readRef(companion, IFC('AuthClient.updateUser'));
8641+
assert(
8642+
r.surface === null && /AMBIGUOUS/.test(r.refusal ?? '') && /opens 2 object literals and interface bodies/.test(r.refusal ?? ''),
8643+
`TSO-I17: THE COMPANION OBJECT -- \`interface X\` plus an object literal \`X = {\` is AMBIGUOUS across kinds: the segment names two bodies, and walking the object literal (as before interfaces were containers) would be a silent pick. Got: ${JSON.stringify(r)}`,
8644+
);
8645+
}
8646+
const HDR_TYPES = (ret) =>
8647+
'export interface SortableRowsProps<T extends { id: string }> {\n' +
8648+
' items: readonly T[];\n' +
8649+
' onReorder: (ids: string[]) => void;\n' +
8650+
` renderRow: (item: T, drag: RowDragProps) => ${ret};\n` +
8651+
'}\n';
8652+
const HDR = (spelling) => `packages/client/src/rows.ts#${spelling}`;
8653+
{
8654+
const r = readRef(HDR_TYPES('React.ReactNode'), HDR('SortableRowsProps.renderRow'));
8655+
assert(
8656+
r.refusal === null && r.surface?.type === 'React.ReactNode' && r.surface?.erased === false,
8657+
`TSO-I18: an interface whose TYPE-PARAMETER CONSTRAINT is a type literal resolves its function-typed property to its return annotation, never "carries NO return annotation" (the app-shell \`SortableFavoriteRowsProps.renderRow\` shape). Got: ${JSON.stringify(r)}`,
8658+
);
8659+
}
8660+
const HDR_FIXTURE = (baseRet) => ({
8661+
pkgs: TSO_PKGS,
8662+
baseFiles: { 'packages/client/src/rows.ts': HDR_TYPES(baseRet) },
8663+
files: {
8664+
'packages/client/src/rows.ts': HDR_TYPES('React.ReactElement'),
8665+
'.changeset/x.md': CS({
8666+
bumps: [['@objectstack/client', 'minor']],
8667+
body: 'fix(client): type the sortable rows\' render callback\n\n' +
8668+
'**BREAKING**: `SortableRowsProps.renderRow` now returns `React.ReactElement`.\n\n' +
8669+
'## Migration\n\n| you wrote | write instead |\n| --- | --- |\n| `renderRow={() => null}` | `renderRow={() => <></>}` |\n' +
8670+
`\n<!-- adr-0087: not-required (type-surface-only ${HDR('SortableRowsProps.renderRow')}) ${TSO_WHY} -->\n`,
8671+
}),
8672+
},
8673+
});
8674+
red('TSO-I19 a CONCRETE base behind a header type literal is refused as not narrowed-from-erased -- both revs are READ through the header, neither is called unannotated',
8675+
run(mk(HDR_FIXTURE('React.ReactNode'))),
8676+
[/predicate 4: narrowed-from-erased\] is FALSE/]);
8677+
green('TSO-I20 the admitted counterpart -- a truly erased base (`=> any`) narrowed behind the same header is admitted, the HEAD side read as annotated',
8678+
run(mk(HDR_FIXTURE('any'))));
8679+
85248680
// ---- The #22918 category: `runtime-export-retired` -------------------------
85258681
//
85268682
// The fixture is the worked example in miniature: `@objectstack/plugin-email`

0 commit comments

Comments
 (0)