-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Bug: [no-base-to-string] generate error with type filter above #11011
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
Comments
Why do you expect there to be no error here? |
But So in that particular case, there's no |
Hover over the type and you'll see what TS narrows it to and why my comment will apply. |
So, if I read between the lines, I'd rather should report that to typescript? |
You can try but likely this would be considered working as intended on their part. In theory maybe something like In any case, for our part, there's no generalizable way to distinguish between |
Functions always have |
Oh, yeah. I couldn't remember whether it was "technically not all functions are |
Thanks @kirkwaiblinger for all the explanations and the context. For the record a simple fix is to test both for nullness AND typeof. export const errorMessage = (error: unknown): string => {
if (error !== null && typeof error === 'object') return JSON.stringify(error);
return String(error);
}; |
Before You File a Bug Report Please Confirm You Have Done The Following...
Playground Link
https://typescript-eslint.io/play/#ts=5.8.2&fileType=.tsx&code=MYewdgzgLgBApgJwSBBZOEIEMDmcYC8MAFIsggFwwCuYA1mCAO5gCUV0CAlmDoQHwwA3gCgYMLgDMSUAJ4AHOCGlkUhAkQDkIAEYArOMCibWMBHCjUEYGACkAygHkAcgDpOPHFNmkkKVgDcYmYWVjb2UNy8vuSBIgC%2BQUA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1oCMBDZRLXxdk%2BKkwDm6KImjQO0SODABfECqA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false
Repro Code
ESLint Config
tsconfig
Expected Result
No error
Actual Result
'error' may use Object's default stringification format ('[object Object]') when stringified. 3:17 - 3:22
Additional Info
Could be related to the fact that typescript consider the object to be
{} | undefined
after the testThe text was updated successfully, but these errors were encountered: