Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Closed
Description
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I haveread the FAQ and my problem is not listed.
Repro
// .eslintrc.jsconstpath=require('path');module.exports={root:true,parser:'@typescript-eslint/parser',plugins:['@typescript-eslint','promise'],parserOptions:{project:[path.resolve(__dirname,'tsconfig.json')]},extends:['next','airbnb-typescript','airbnb/hooks','plugin:@typescript-eslint/eslint-recommended','plugin:@typescript-eslint/recommended','plugin:@typescript-eslint/recommended-requiring-type-checking','plugin:promise/recommended','prettier',],env:{browser:true,node:true,},};
// lib/message.tsclassMessage{publictoString():string{return'I am a custom toString() method';}}constmessage=newMessage();console.log(`This is the message:${message}`);// results in an errorconsole.log(`This is the message:${message.toString()}`);// no error
That ☝️ creates an error saying:
Invalid type "Message" of template literal expression.// tsconfig.json{"$schema":"http://json.schemastore.org/tsconfig","compilerOptions": {"target":"es5","lib": ["dom","dom.iterable","esnext"],"allowJs":false,"skipLibCheck":true,"strict":true,"noUnusedLocals":true,"noImplicitAny":true,"noImplicitReturns":true,"noImplicitThis":true,"allowSyntheticDefaultImports":true,"forceConsistentCasingInFileNames":true,"noEmit":true,"esModuleInterop":true,"module":"esnext","moduleResolution":"node","resolveJsonModule":true,"isolatedModules":true,"jsx":"preserve","downlevelIteration":true,"baseUrl":"." },"exclude": ["node_modules"],"include": ["next-env.d.ts","types/*.d.ts","lib/**/*.ts","lib/**/*.tsx","components/**/*.ts","components/**/*.tsx","pages/**/*.ts","pages/**/*.tsx","styles/**/*.ts" ]}
Expected Result
There should be no error because theno-base-to-string rule should apply here; ESLint should realize that I've defined a customtoString() method onMessage and thusMessage is a valid type to be in a template expression.
Actual Result
I got this error from ESLint:
Invalid type "Message" of template literal expression.Versions
| package | version |
|---|---|
@typescript-eslint/eslint-plugin | 4.27.0 |
@typescript-eslint/parser | 4.27.0 |
TypeScript | 4.3.2 |
ESLint | 7.28.0 |
node | 12.8.3 |