Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[restrict-template-expressions] errors even when class definestoString() #3538

Closed
Labels
package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginworking as intendedIssues that are closed as they are working as intended
@nicholaschiang

Description

@nicholaschiang
  • 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

packageversion
@typescript-eslint/eslint-plugin4.27.0
@typescript-eslint/parser4.27.0
TypeScript4.3.2
ESLint7.28.0
node12.8.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginworking as intendedIssues that are closed as they are working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp