镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Inferred never values don't properly type guard #60185

Description

🔎 Search Terms

never type guard

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about type guarding

⏯ Playground Link

https://www.typescriptlang.org/play/?noUncheckedIndexedAccess=true&moduleResolution=99&target=99&module=199&exactOptionalPropertyTypes=true&ts=5.6.3#code/GYVwdgxgLglg9mABAExgUwBQEoBcixoBuaATogN4BQiNiJaUIJSYIANm4gIYDO+RpANyUAvpUqhIsBIhhhgpACLpsFarXqNmKFVmFjKyNBDZd6iCAh5READzzWScgOaIAPvnZthlGMEQYAIS2WGq0svJKuvritoKIAPQJdrJ81jAciAAOcDw8MABGbACenhzifgHBoVThqJh6orHxSSlgcADuFlxgAOQ2BWhlbEA

💻 Code

function die(): never {
    return null as never;
}

function inferDie() {
    return die();
}

declare const x: string | null;

if (!x) {
    inferDie();
}

x; // x is still possibly null

if (!x) {
    die();
}

x; // x now can't be null

🙁 Actual behavior

Two functions that have "identical" signatures, () => never, are not acting the same

🙂 Expected behavior

I'd expect both of these to act the same way since, for everything I can see, TS sees their signatures as being identical.

Additional information about the issue

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions