Skip to content

🐛 Bug: Crash in isPropertyReadonlyInType on argument to readonly type parameter (?) #754

@JoshuaKGoldberg

Description

@JoshuaKGoldberg

Bug Report Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have pulled the latest main branch of the repository.
  • I have searched for related issues and found none that matched my issue.

Expected

Calling isPropertyReadonlyInType({ abc: 42 }, "abc") in the following code block should not crash:

declare const fooFactory: <T>(x: readonly T[]) => (f: (x: T) => void) => void;

fooFactory([{ abc: 42 }])((x) => { });

Actual

typescript-eslint/typescript-eslint#11289:

TypeError: Cannot read properties of undefined (reading 'checkFlags')
Occurred while linting /Users/josh/repos/typescript-eslint/packages/eslint-plugin/tests/fixtures/file.ts:4
Rule: "@rule-tester/prefer-readonly-parameter-types"
 ❯ isTransientSymbolLinksFlagSet ../../node_modules/ts-api-utils/lib/index.cjs:143:26
 ❯ isInConstContext ../../node_modules/ts-api-utils/lib/index.cjs:994:16
 ❯ ../../node_modules/ts-api-utils/lib/index.cjs:1088:464
 ❯ symbolHasReadonlyDeclaration ../../node_modules/ts-api-utils/lib/index.cjs:1087:145
 ❯ ../../node_modules/ts-api-utils/lib/index.cjs:1172:5
 ❯ isReadonlyPropertyIntersection ../../node_modules/ts-api-utils/lib/index.cjs:1154:23
 ❯ Object.isPropertyReadonlyInType ../../node_modules/ts-api-utils/lib/index.cjs:1059:41
 ❯ isTypeReadonlyObject ../type-utils/dist/isTypeReadonly.js:138:25

Additional Info

The specific crash is in:

ts-api-utils/src/flags.ts

Lines 96 to 101 in 7935007

export function isTransientSymbolLinksFlagSet(
links: ts.TransientSymbolLinks,
flag: ts.CheckFlags,
): boolean {
return isFlagSet(links.checkFlags, flag);
}

...but the root is that undefined is getting used instead of a value, somewhere in the stack.

💖

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: accepting prsPlease, send a pull request to resolve this! 🙏type: bugSomething isn't working 🐛

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions