8000 [no-explicit-any] False positive for type predicates · Issue #1048 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content
[no-explicit-any] False positive for type predicates #1048
Closed
@leximayfield

Description

@leximayfield

Repro

{
	"parser": "@typescript-eslint/parser",
	"extends": [
		"plugin:@typescript-eslint/recommended"
	]
}
interface Foo {
	bar: number;
}

export const isFoo = (x: any): x is Foo => {
	if (typeof x.bar !== 'number') {
		return false;
	}
	return true;
}

Expected Result
No lint issues.

Actual Result

  5:26  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any

Additional Info
An any type should be allowed as a function parameter when writing a type predicate, as it is reasonable for the function to take an any and narrow the type based on some condition inside the function. Typescript 3.7 is going to have type assertion functions, and those should probably also allow the any type.

Versions

package version
@typescript-eslint/eslint-plugin 2.3.2
@typescript-eslint/parser 2.3.2
TypeScript 3.6.3
ESLint 6.5.1
node 12.11.0
npm 6.11.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

      0