File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -33,6 +33,10 @@ export default abstract class Optional<T> {
3333 }
3434
3535 static ofNonNull < T > ( payload : T ) : Optional < T > {
36+ return Optional . of ( payload ) ;
37+ }
38+
39+ static of < T > ( payload : T ) : Optional < T > {
3640 if ( payload !== null && payload !== undefined )
3741 return new PresentOptional < T > ( payload ) ;
3842 else
Original file line number Diff line number Diff line change 11{
22 "name" : " typescript-optional" ,
3- "version" : " 1.5 .0" ,
3+ "version" : " 1.6 .0" ,
44 "description" : " Optional (like Java) implementation in TypeScript" ,
55 "repository" : {
66 "type" : " git" ,
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ describe("Optional", () => {
2727 } ) ;
2828 } ) ;
2929
30- describe ( "#ofNonNull " , ( ) => {
30+ describe ( "#of " , ( ) => {
3131 it ( "returns a present optional when it is given a non-null value." , ( ) => {
3232 let sut = Optional . ofNonNull ( "foo" ) ;
3333 assert ( sut . isPresent ) ;
@@ -42,6 +42,21 @@ describe("Optional", () => {
4242 } ) ;
4343 } ) ;
4444
45+ describe ( "#of" , ( ) => {
46+ it ( "returns a present optional when it is given a non-null value." , ( ) => {
47+ let sut = Optional . of ( "foo" ) ;
48+ assert ( sut . isPresent ) ;
49+ } ) ;
50+
51+ it ( "throws an exception when it is given null." , ( ) => {
52+ assert . throws ( ( ) => Optional . of < string | null > ( null ) )
53+ } ) ;
54+
55+ it ( "throws an exception when it is given undefined." , ( ) => {
56+ assert . throws ( ( ) => Optional . of < string | undefined > ( undefined ) )
57+ } ) ;
58+ } ) ;
59+
4560 describe ( "#empty" , ( ) => {
4661 it ( "returns an empty optional." , ( ) => {
4762 let sut : Optional < string > = Optional . empty ( ) ;
You can’t perform that action at this time.
0 commit comments