Skip to content

Type guard fails to determine non null tuple property #59784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
irdkwmnsb opened this issue Aug 28, 2024 · 1 comment
Closed

Type guard fails to determine non null tuple property #59784

irdkwmnsb opened this issue Aug 28, 2024 · 1 comment

Comments

@irdkwmnsb
Copy link

πŸ”Ž Search Terms

"ts2322" "tuples" "null type guard"

πŸ•— Version & Regression Information

Typescript version 5.5.4

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.7.0-dev.20240828#code/C4TwDgpgBAIghsCAlOA7A5hAKuaBeKAbXkSgB8pUBXAGxoBpYFoLq6BdAKE4GMB7VAGdgUAE5pMALiaIUGbLigFCqCAHcZEABQBKRqo0ltO9gG5u-ISMTClUXUoB8UAN6coHqAEsAZvfHyhAAM7Ep4BGw05BQBmIQAjKHhEbQ0Oq7unlmiEMBUoqjmWQC+mR6WtgBG0sTMjEZJYhIQplAA9G1QWADKUABMAMx9fZzFQA

πŸ’» Code

type DateRangeType = [Date | null, Date | null]

const range: DateRangeType = [new Date(), new Date()];

const test = () => {
    if (range[0] === null || range[1] === null) {
        return;
    }
    const b: [Date, Date] = range; // TS 2322
}

πŸ™ Actual behavior

Error on line const b: [Date, Date] = range; // TS 2322

πŸ™‚ Expected behavior

Type of range would be narrowed down to [Date, Date]

Additional information about the issue

No response

@jcalz
Copy link
Contributor

jcalz commented Aug 28, 2024

Duplicate of #42384

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants