You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const optionalEmpty2 =Optional.empty<string>(); // or parameterize explicitly
50
50
```
51
51
52
-
53
-
54
52
### operations
55
53
56
54
```ts
@@ -122,28 +120,28 @@ optional.toOption();
122
120
### prototype-free types
123
121
124
122
While `Optional`'s fluent interface for method chaining with `prototype` is usually useful and elegant,
125
-
relying on `prototype` can cause some problems in certain situations like an external function that copies such objects *except*`prototype`.
126
-
For example, `setState` of React reflects the given value as a state except its`prototype` (and then you will see "TypeError: undefined is not a function" in runtime though TypeScript compilation has been succeeded!).
123
+
relying on `prototype` can cause some problems in certain situations like that an external function copies such objects *except*`prototype`.
124
+
For example, `setState` of React reflects the given value as a state except the value's`prototype` (and then you will see "TypeError: undefined is not a function" in runtime though TypeScript compilation has been succeeded!).
127
125
128
-
To avoid this issue, you have three options that *open* an `Optional` into a *prototype-free*, or a simple JavaScript object (associative array, string etc.).
126
+
To avoid this issue, you have three options that *convert* an `Optional` into a *prototype-free*, or a simple JavaScript object (associative array, string etc.).
129
127
130
-
-`Option.orNull`
131
-
-`Option.orUndefined`
132
-
-`Option.toOption`
128
+
-`Optional.orNull`
129
+
-`Optional.orUndefined`
130
+
-`Optional.toOption`
133
131
134
-
#### `Option.orNull` and `Option.orUndefined`
132
+
#### `Optional.orNull` and `Optional.orUndefined`
135
133
136
-
Using `Option.orNull` or `Option.orUndefined` is the simple way to obtain prototype-free objects.
137
-
These methods convert an Optional<T> into a value of *type union*.
134
+
Using `Optional.orNull` or `Optional.orUndefined` is the simple way to obtain prototype-free objects.
135
+
These methods convert an `Optional<T>` into a value of *type union*.
138
136
139
-
`Option<T>.orNull` returns `T | null`.
137
+
`Optional<T>.orNull` returns `T | null`.
140
138
141
139
`Optional<T>.orUndefined` returns `T | undefined`. The `T | undefined` type is compatible with [optional parameters and properties](http://www.typescriptlang.org/docs/handbook/advanced-types.html#optional-parameters-and-properties) of TypeScript.
142
140
143
141
Use `Optional.ofNullable` to restore an Optional value from a value of these type unions.
144
142
145
143
```ts
146
-
const update: <T> (original:T) =>T=/* some external function */
144
+
const update: <T> (original:T) =>T=/* some external function that returns without the prototype */
147
145
const optional:Optional<string> =/* some Optional object */;
As a more explicit way to obtain prototype-free objects, `Optional.toOption` is provided.
164
+
This method convert an `Optional<T>` into an object of `Option<T>` type, which conforms to [*discriminated unions*](http://www.typescriptlang.org/docs/handbook/advanced-types.html#discriminated-unions) also known as *algebraic data types*.
165
+
Refer the [API document](lib/types.ts) of `Option<T>` to learn about the structure.
166
+
165
167
```ts
168
+
const update: <T> (original:Option<T>) =>T=/* some external function that returns without the prototype */
166
169
const optional:Optional<string> =/* some Optional value */;
0 commit comments