Skip to content

[@typescript-eslint/no-base-to-string] is complaining about boolean values #1655

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

Closed
juergenzimmermann opened this issue Feb 29, 2020 · 9 comments · Fixed by #1850
Closed
Labels
bug Something isn't working external This issue is with another package, not typescript-eslint itself has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@juergenzimmermann
Copy link

Are you opening an issue because the rule you're trying to use is not found?
No

Repro

Rule definition in YAML

@typescript-eslint/no-base-to-string": error

Blamed TypeScript code fragment:

const result = compareSync(password, user.password); // result is of type boolean
logger.error(`AuthService.checkPassword(): ${result}`);

Expected Result
No output

Actual Result
152:51 error 'result will evaluate to '[Object object]' when stringified @typescript-eslint/no-base-to-string

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 2.21.1-alpha.5
@typescript-eslint/parser 2.21.1-alpha.5
TypeScript 3.8.3
ESLint 7.0.0-alpha.2
node 13.9.0
npm 6.14.1
@juergenzimmermann juergenzimmermann added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Feb 29, 2020
@bradzacher
Copy link
Member

Could you provide more information?
The type defs for everything would be great.

A small, self contained repro would be better.

@bradzacher bradzacher added awaiting response Issues waiting for a reply from the OP or another party and removed triage Waiting for team members to take a look labels Feb 29, 2020
@leaumar
Copy link

leaumar commented Mar 2, 2020

I can provide a live example: please check this PR (yarn install && yarn lint to reproduce)

The rule is complaining at Restrictions.ts:59 about a boolean in a template string

image
image

@felixfbecker
Copy link

Saw the same - I would expect the no-base-to-string to only be used for object types, as restrict-template-expression can already take care of the other

@bradzacher
Copy link
Member

This is a bug.

Self-contained repro is `${true}`.

The rule grabs the toString property's declaration for the given type, and then asserts that the declaration does not come from the base Object type.

For some reason, boolean types return Object instead of Boolean.

For comparison, for both `${''}` and `${1}` the owner of the parent type is String and Number.

It seems like this bug is caused by a bug in typescript itself..

@bradzacher bradzacher added bug Something isn't working external This issue is with another package, not typescript-eslint itself and removed awaiting response Issues waiting for a reply from the OP or another party labels Mar 2, 2020
@felixfbecker
Copy link

Maybe we should open an issue at the TS repo with a combined list of types with missing toString()? URLSearchParams also misses it

@bradzacher
Copy link
Member

feel free if you'd like!

We can't rely on a forward fix for this plugin, as that adds a ~3month turnaround on the fix, and forces people to upgrade their TS version (with breaking changes), so the rule will have to be fixed to workaround regardless.

@felixfbecker
Copy link

felixfbecker commented Mar 2, 2020

I'd rather have a fix sooner than later too :)

Also noticed with RegExp and URL (and URLSearchParams as mentioned above)

@bradzacher
Copy link
Member

bradzacher commented Apr 8, 2020

note that URL already has a toString defined: https://github.com/microsoft/TypeScript/blob/d209092ccc0ca9fee4fe5148c554484aab95e487/lib/lib.dom.d.ts#L16101
as does URLSearchParams: https://github.com/microsoft/TypeScript/blob/d209092ccc0ca9fee4fe5148c554484aab95e487/lib/lib.dom.d.ts#L16152

RegExp does not though


I tested URL and URLSearchParams against master using the dom lib, and they passed tests fine - so there might be something to do with your setup that's causing them to fail.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working external This issue is with another package, not typescript-eslint itself has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants