Skip to content

Redundant checks on unions #1679

@a-non-a-mouse

Description

@a-non-a-mouse

📝 Summary

Write a short summary of the bug in here.

  • Typia Version: 9.7.2
  • Expected behavior: Concise checks
  • Actual behavior: Redundant checks

Unions result in redundant checks, effectively if(type === 'A') { if (type === 'A' && ...) { ... } }

⏯ Playground Link

playground

💻 Code occuring the bug

import typia, { tags } from "typia";

type Orange = { name: 'Orange', color: 'orange' };
type Apple = { name: 'Apple', color: 'red' | 'green' };
type Banana = { name: 'Banana', color: 'yellow' };

type Fruit = Orange | Apple | Banana;

declare const fruit: Fruit;
typia.is<Fruit>(fruit);

generates:

...
  const _io2 = (input) => "Banana" === input.name && "yellow" === input.color;
  const _iu0 = (input) =>
    (() => {
      if ("Banana" === input.name) return _io2(input);
...

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions