Skip to content

Commit bb84cf1

Browse files
authored
Merge pull request #7 from valbeat/feat/improve-type-annotations
feat: improve PHPStan type annotations for Result interface
2 parents 0676115 + 66a3a4a commit bb84cf1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/Result.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ interface Result
1616
* 結果が成功(Ok)の場合に true を返します.
1717
*
1818
* @phpstan-assert-if-true Ok<T> $this
19+
* @phpstan-assert-if-false Err<E> $this
1920
*
2021
* @return bool
2122
*/
@@ -34,6 +35,7 @@ public function isOkAnd(callable $fn): bool;
3435
* 結果が失敗(Err)の場合に true を返します.
3536
*
3637
* @phpstan-assert-if-true Err<E> $this
38+
* @phpstan-assert-if-false Ok<T> $this
3739
*
3840
* @return bool
3941
*/
@@ -51,14 +53,14 @@ public function isErrAnd(callable $fn): bool;
5153
/**
5254
* 成功値を返します。失敗の場合は例外を投げます.
5355
*
54-
* @return T
56+
* @return ($this is Ok<T> ? T : never)
5557
*/
5658
public function unwrap(): mixed;
5759

5860
/**
5961
* エラー値を返します。成功の場合は例外を投げます.
6062
*
61-
* @return E
63+
* @return ($this is Err<E> ? E : never)
6264
*/
6365
public function unwrapErr(): mixed;
6466

@@ -67,7 +69,7 @@ public function unwrapErr(): mixed;
6769
*
6870
* @template U
6971
* @param U $default
70-
* @return T|U
72+
* @return ($this is Ok<T> ? T : U)
7173
*/
7274
public function unwrapOr(mixed $default): mixed;
7375

0 commit comments

Comments
 (0)