Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Bug: isPropertyReadonlyInType crashes on a mapped type parameter extending any #17

Closed
3 tasks done
JoshuaKGoldberg opened this issue Feb 6, 2023 · 0 comments · Fixed by #18
Closed
3 tasks done
Assignees
Labels
status: accepting prs Please, send a pull request to resolve this! 🙏 type: bug Something isn't working :( 🐛

Comments

@JoshuaKGoldberg
Copy link
Owner

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

isPropertyReadonlyInType shouldn't crash if provided a type that doesn't have a modifiersType property. Per ajafff/tsutils#136 (comment) that's actually possible.

type MyType<T> = {
  [K in keyof T]: 'cat' | 'dog' | T[K];
};

function method<A extends any[] = string[]>(value: MyType<A>) {
  return value;
}

Actual

Per typescript-eslint/typescript-eslint#3405:

TypeError: Cannot read properties of undefined (reading 'flags')
 ❯ Module.isUnionType src/types/typeGuards.ts:39:15
     37| 
     38| export function isUnionType(type: ts.Type): type is ts.UnionType {
     39|  return (type.flags & ts.TypeFlags.Union) !== 0;
       |               ^
     40| }
     41| 
 ❯ unionTypeParts src/types/utilities.ts:243:9
 ❯ isPropertyReadonlyInType src/types/utilities.ts:132:24
 ❯ isReadonlyPropertyFromMappedType src/types/utilities.ts:98:32
 ❯ src/types/utilities.ts:61:12
 ❯ someTypePart src/types/utilities.ts:218:55
 ❯ isReadonlyPropertyIntersection src/types/utilities.ts:52:9
 ❯ Module.isPropertyReadonlyInType src/types/utilities.ts:146:4

Additional Info

Reproduction steps:

  1. Clone https://github.com/typescript-eslint/typescript-eslint locally
  2. Switch to its v6 branch and run yarn
  3. Add that test case to prefer-readonly-parameter-types.test.ts
  4. Run yarn jest require-await in packages/eslint-plugin
@JoshuaKGoldberg JoshuaKGoldberg added status: accepting prs Please, send a pull request to resolve this! 🙏 type: bug Something isn't working :( 🐛 labels Feb 6, 2023
@JoshuaKGoldberg JoshuaKGoldberg self-assigned this Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepting prs Please, send a pull request to resolve this! 🙏 type: bug Something isn't working :( 🐛
Projects
None yet
1 participant