π Search Terms
narrow uninitialized, uninitialized undefined
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about
initialized/uninitialized
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.9.0-dev.20250326#code/MYewdgzgLgBAZiEMC8MAUUDuIBcNoBOAlmAOYCUeAbiEQCYoB8MA3gFAwwBEArhAKb4oxYFC4BuDjCkB6GTH4QANiSgBaOkQgBDAEZL+asPwAe6lcZgABKAE8ADouDF76xRagySRdXX7AlbQJtKCJwCCkDWHB+PEISUhgAHxgeMD84En46SSkiOHQYlGRULBByVilOORgAPQB+KpgagDlEeykAXzZutgQQNC4ucnEgA
π» Code
const foo = (two: string): void => {
"use strict";
// eslint-disable-next-line @typescript-eslint/init-declarations
let one: string | undefined;
if (one === two) {
// ^? let one: string | undefined
// Noop
}
}
foo("");
π Actual behavior
The type is not narrowed, which prevents typescript-eslint from flagging this comparison that always fails: typescript-eslint playground
π Expected behavior
The one === two comparison should be flagged because it always returns false (there is no way one has any value other than undefined).
Additional information about the issue
Also filed a related issue with ESLint: eslint/eslint#19581
π Search Terms
narrow uninitialized, uninitialized undefined
π Version & Regression Information
initialized/uninitializedβ― Playground Link
https://www.typescriptlang.org/play/?ts=5.9.0-dev.20250326#code/MYewdgzgLgBAZiEMC8MAUUDuIBcNoBOAlmAOYCUeAbiEQCYoB8MA3gFAwwBEArhAKb4oxYFC4BuDjCkB6GTH4QANiSgBaOkQgBDAEZL+asPwAe6lcZgABKAE8ADouDF76xRagySRdXX7AlbQJtKCJwCCkDWHB+PEISUhgAHxgeMD84En46SSkiOHQYlGRULBByVilOORgAPQB+KpgagDlEeykAXzZutgQQNC4ucnEgA
π» Code
π Actual behavior
The type is not narrowed, which prevents typescript-eslint from flagging this comparison that always fails: typescript-eslint playground
π Expected behavior
The
one === twocomparison should be flagged because it always returns false (there is no wayonehas any value other thanundefined).Additional information about the issue
Also filed a related issue with ESLint: eslint/eslint#19581