-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed as not planned
Closed as not planned
Copy link
Labels
bugSomething isn't workingSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugintriageWaiting for team members to take a lookWaiting for team members to take a lookworking as intendedIssues that are closed as they are working as intendedIssues that are closed as they are working as intended
Description
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
Repro Code
// From https://github.com/sindresorhus/type-fest/blob/HEAD/source/set-non-nullable.d.ts
export type SetNonNullable<BaseType, Keys extends keyof BaseType = keyof BaseType> = {
[Key in keyof BaseType]: Key extends Keys
? NonNullable<BaseType[Key]>
: BaseType[Key];
};
export const nonNullish = <T>(value: T | null | undefined): value is T => value != null;
export const hasNonNullishField = <T, K extends keyof T>(
obj: T,
key: K,
): obj is SetNonNullable<T, K> => nonNullish(obj[key]); // <--
ESLint Config
{
"rules": {
"@typescript-eslint/no-unnecessary-condition": ["error", { "checkTypePredicates": true }]
}
}
tsconfig
Expected Result
The type of obj[key]
in the example can be nullish and therefore the error should not be reported.
Actual Result
The error is reported.
Additional Info
No response
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugintriageWaiting for team members to take a lookWaiting for team members to take a lookworking as intendedIssues that are closed as they are working as intendedIssues that are closed as they are working as intended