Skip to content

Commit 408a794

Browse files
fix: allow null types in constructor and maybe() (#175)
BREAKING CHANGE: allow null types in constructor and maybe()
1 parent 037e802 commit 408a794

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/maybe/maybe.factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Maybe } from './maybe'
22
import { IMaybe } from './maybe.interface'
33

4-
export function maybe<T>(value?: T): Maybe<T> {
4+
export function maybe<T>(value?: T | null): Maybe<T> {
55
return new Maybe<T>(value)
66
}
77

src/maybe/maybe.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ describe('Maybe', () => {
6666
})
6767

6868
it('should handle "some" case when input is null', () => {
69-
const sut = null as string | undefined | null
70-
const maybeAString = maybe(sut).valueOr('default output')
69+
const sut: string | null = null
70+
const maybeAString = maybe<string>(sut).valueOr('default output')
7171

7272
expect(maybeAString).toEqual('default output')
7373
})
7474

7575
it('should handle "some" case when input is ""', () => {
76-
const sut = '' as string | undefined | null
76+
const sut: string | undefined | null = ''
7777
const maybeAString = maybe(sut).valueOr('fallback')
7878

7979
expect(maybeAString).toEqual('')

src/maybe/maybe.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { IMaybePattern, IMaybe } from './maybe.interface'
22

33
export class Maybe<T> implements IMaybe<T> {
44

5-
constructor(private readonly value?: T) { }
5+
constructor(private readonly value?: T | null) { }
66

77
public of(value: T): IMaybe<T> {
88
return new Maybe<T>(value)

0 commit comments

Comments
 (0)