[prefer-readonly-parameter-types] unique symbols as interface keys causes eslint to crash #2143
Labels
bug
Something isn't working
package: eslint-plugin
Issues related to @typescript-eslint/eslint-plugin
Repro
tsconfig.json
package.json
.eslintrc.json
test.ts
Test command:
eslint . --ext .ts
Expected Result
eslint . --ext .ts
should not crash (successfully lint code) and for the given minimal rule set above, should not return any errors.Actual Result
Additional Info
(I'll save the noise of dumping the debug output, but can provide if requested)
The error is being emitted here: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/src/util/isTypeReadonly.ts#L104-L105
(So I don't think it is explicitly related to
prefer-readonly-parameter-types
, but it is one that successfully recreates the error).My understanding is the purpose of this check is to ensure that properties being referenced are defined in the root type.
In my case, the only property is a "unique symbol" that typescript has aliased as
__@sym@10
.So
property.getName()
=>__@sym@10
.I can't find any documentation for Typescript's checker, besides the raw source code but that
getTypeOfPropertyOfType
on checker is defined as a higher order functiongetTypeOfPropertyOfType: (type, name) => getTypeOfPropertyOfType(type, escapeLeadingUnderscores(name)),
Note the
escapeLeadingUnderscores
which basically transforms__@sym@10
=>___@sym@10
(three underscores at start). That key is not present in thetype.members
map, so it returns undefined and results in a thrown error.Due to typescript's handling of double underscore, this could be a typescript error, but the code compiles and is valid in typescript, so I imagine there is a correct way around this. The decision to prepend double underscore and not pre-escape the value feels like a conscious decision on their part.
All I've been able to do so far is understand why the error is happening... I can't claim I really understand the logic behind the code design, or an alternative solution.
e.g. is there an alternative to
getTypeOfPropertyOfType
that handles this edge case? Or is that call even necessary to perform readonly logic?I'd be happy to help with a PR, but I as I said I can't find any decent documentation for Typescript's checker, so I don't even know where to start.
Versions
@typescript-eslint/eslint-plugin
3.0.2
@typescript-eslint/parser
3.0.2
TypeScript
3.9.3
ESLint
7.1.0
node
14.3.0
npm
6.14.5
The text was updated successfully, but these errors were encountered: