-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commitlint: do not use empty class for None
Empty classes result in strange issues that turn the TS compiler into not very helpful. E.g.: https://stackoverflow.com/questions/78953267/why-is-typescript-not-throwing-a-compile-time-error-when-constructor-is-not-used NOTE: we still mark the new methods as deprecated to give a hint that `instanceof` usage is better. These tooltips will be properly shown by IDEs and linters according to: https://stackoverflow.com/a/62991642/544947
- Loading branch information
Showing
2 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,35 @@ | ||
export class None {} | ||
interface IOption { | ||
/** | ||
* @deprecated it is better to use `if (foo instanceof None)` so that you can access the .value in the `else` case | ||
**/ | ||
IsNone(): boolean; | ||
/** | ||
* @deprecated it is better to use `if (!(foo instanceof None))` so that you can access the .value inside the `if` block | ||
**/ | ||
IsSome(): boolean; | ||
} | ||
|
||
export class None { | ||
public IsNone(): boolean { | ||
return true; | ||
} | ||
public IsSome(): boolean { | ||
return false; | ||
} | ||
} | ||
export class Some<T> { | ||
value: T; | ||
|
||
constructor(val: T) { | ||
this.value = val; | ||
} | ||
|
||
public IsNone(): boolean { | ||
return false; | ||
} | ||
public IsSome(): boolean { | ||
return true; | ||
} | ||
} | ||
export type Option<T> = None | Some<T>; | ||
|
||
export type Option<T> = (None | Some<T>) & IOption; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters