Skip to content
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

[@typescript-eslint/no-unnecessary-type-assertion] False positives for "as const" assertions with template literals #8737

Closed
4 tasks done
klassm opened this issue Mar 20, 2024 · 2 comments · Fixed by #8740
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@klassm
Copy link

klassm commented Mar 20, 2024

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.4.2&fileType=.tsx&code=KYDwDg9gTgLgBAYwgOwM7zFCAjANsAWwClUUAVATzGAFUoBLABSmADN6Q4BeOAcgAsYMMKgBcAenHAoWKKgB0-CAWABaJMmTAEMeUgLjecAIapEKdAG4AsACgN6ONNkAhU7Qbc4AAwAkAb0wcfGJSZEpqOiYWdhAAXw0YYGQYVGkAN3oEYFRvEzMHGBtbO1BIWDgYKmA4ZmDCEhQvACVtaAATAB50BmQAcwAaOABXZABrZAgAd2QAPjgAMjh-OzhK6tEfAKrqCFY4ILwGsIiPaLYOOICe%2Bn648WuYXr6472K44tLwaHhCuAA1Yy4ejtYwwegoACiMmgmzqR1CTR4K1sax2wE2fn8zmgbjSUXu6SBILBEOQqhxUG8AzsHzsQA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tiacTJTIAhtEK0ipWkOTJE0fJQ5N0UOdA7RI4MAF8QOoA&tsconfig=N4KAvkA&tokens=false

Repro Code

export const problemJsonTypeUriPrefix = 'https://errors.home-connect.com/';
const errorBaseUri = `${problemJsonTypeUriPrefix}contentservices` as const;

export type ProblemJson = Record<string, unknown> & {
  type: `${typeof problemJsonTypeUriPrefix}${string}/${string}`;
};

export const ValidationError: ProblemJson = {
  type: `${errorBaseUri}/validation-error`,
};

ESLint Config

module.exports = {
  "rules": {
    "@typescript-eslint/no-unnecessary-type-assertion": "error"
  }
}

tsconfig

{
}

Expected Result

The as const is kept.

Actual Result

The as const is marked as unnecessary.

Additional Info

See comment here.

@klassm klassm added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Mar 20, 2024
@bradzacher bradzacher changed the title [@typescript-eslint/no-unnecessary-type-assertion] False positives for "as const" assertions [@typescript-eslint/no-unnecessary-type-assertion] False positives for "as const" assertions with template literals Mar 20, 2024
@bradzacher bradzacher added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for maintainers to take a look labels Mar 20, 2024
@SimonSchick

This comment has been minimized.

@typescript-eslint typescript-eslint deleted a comment from github-actions bot Mar 20, 2024
@bradzacher
Copy link
Member

@SimonSchick as per the issue - you want #8721, not this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
3 participants