Skip to content

[no-unsafe-assignment/return] Relax restrictions to allow any => unknown assignment #2325

Closed
@ghost

Description

Repro

function myFunction(): unknown {
    // triggers no-unsafe-assignment because JSON.parse returns any
    let val: unknown = JSON.parse(someStringVar);

    // triggers no-unsafe-return because JSON.parse returns any
    return JSON.parse(someStringVar);
}

Expected Result

This should not throw an error because a direct any => unknown cast cannot possibly be unsafe. Requiring an as unknown everywhere is unnecessary noise.

Additional notes

Ideally, any should not be used across a code base, and I like that the current default rules enforce this. However, a lot of existing APIs still use any, including the TypeScript library itself, and we have to make do with what we have.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestgood first issueGood for newcomershas 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