Skip to content

[no-unnecessary-type-assertion] false positive when asserting via non-null assertion operator #529

@vkrol

Description

@vkrol

Repro
https://github.com/vkrol/typescript-eslint-no-unnecessary-type-assertion-undefined

module.exports = {
	parser: "@typescript-eslint/parser",
	parserOptions: {
		project: "tsconfig.json",
	},
	plugins: ["@typescript-eslint"],
	rules: {
		"@typescript-eslint/no-unnecessary-type-assertion": "error",
	}
};
declare function foo(str?: string): void;
declare const str: string | null;

foo(str!);

Expected Result
No errors.
Actual Result
Error:

D:\Projects\typescript-eslint-no-unnecessary-type-assertion-undefined\index.ts
  4:5  error  This assertion is unnecessary since the receiver accepts the original type of the expression  @typescript-eslint/no-unnecessary-type-assertion

✖ 1 problem (1 error, 0 warnings)
  1 error and 0 warnings potentially fixable with the `--fix` option.

Additional Info
The change that introduced this regression: #478.

Versions

package version
@typescript-eslint/eslint-plugin 1.9.0
@typescript-eslint/parser 1.9.0
TypeScript 3.4.5
ESLint 5.16.0
node 10.15.3
npm 6.4.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghas prthere is a PR raised to close thispackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy