Skip to content

Add type guard to 'is' and 'is.not' methods #27

@inhibitor1217

Description

@inhibitor1217

As each instances are defined as branded type of the extended enum (#7), type guards should be supported.

enum _Fruit { Apple, Orange }

class Fruit extends extend<typeof _Fruit, _Fruit>(_Fruit) {}

declare const f: Fruit;

if (f === Fruit.Apple) {
  type T = typeof f; // should be Fruit.Apple, it is not working now regardless of type guards
}

if (f.is(Fruit.Apple)) {
  type T = typeof f; // Fruit.Apple
}

if (f.is.not(fruit.Apple)) {
  type T = typeof f; // Exclude<F, Fruit.Apple> or something similar
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions