Skip to content

Runtime Validation With Variables Fails #48241

Closed
@GEMISIS

Description

@GEMISIS

Bug Report

🔎 Search Terms

typescript validation variable boolean failure

🕗 Version & Regression Information

Version 4.6.2 and below all seem to exhibit the same issue. Also confirmed most recent nightly build as of this filing exhibits the same issue.

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

⏯ Playground Link

Playground link with relevant code

💻 Code

  interface test {
      val1: string | undefined;
  }

  function test1(input: string) {
      console.log(input);
  }
  function test2(input: test) {
      const canWork = input.val1 !== undefined;
      // Fails
      if (canWork) {
          test1(input.val1);
      }
      // Succeeds
      if (input.val1 !== undefined) {
          test1(input.val1);
      }
  }

🙁 Actual behavior

Receive the following error for type validation:

Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
  Type 'undefined' is not assignable to type 'string'.(2345)

🙂 Expected behavior

Type validation from the boolean expression should work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions