Skip to content

Commit 1616501

Browse files
committed
docs: Stringifiable
1 parent 2323173 commit 1616501

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -1652,16 +1652,17 @@ They don't alter the runtime behavior of the code, but they can be used to make
16521652

16531653
### Stringifiable
16541654
This type describes any value that either is a string itself or can be converted to a string.
1655-
To be considered stringifiable, the object needs to have a `toString()` method that returns a string (all primitive types have this method).
1656-
This method allows not just explicit conversion by calling it, but also implicit conversion by passing it into the `String()` constructor or by interpolating it in a template string.
1655+
To be considered stringifiable, the object needs to have a `toString()` method that returns a string.
1656+
Most primitives have this method, but something like undefined or null does not (they can only be used in the `String()` constructor or string interpolation).
1657+
Having this method allows not just explicit conversion by calling it, but also implicit conversion by passing it into the `String()` constructor or by interpolating it in a template string.
16571658

16581659
<details><summary><b>Example - click to view</b></summary>
16591660

16601661
```ts
16611662
import type { Stringifiable } from "@sv443-network/userutils";
16621663

16631664
function logSomething(value: Stringifiable) {
1664-
console.log(`Log: ${value}`); // implicit conversion using `value.toString()`
1665+
console.log(`Log: ${value}`); // implicit conversion to a string
16651666
}
16661667

16671668
const fooObject = {
@@ -1678,7 +1679,7 @@ logSomething(true); // "Log: true"
16781679
logSomething(Symbol(1)); // "Log: Symbol(1)"
16791680
logSomething(fooObject); // "Log: hello world"
16801681

1681-
logSomething(barObject); // Type Error
1682+
logSomething(barObject); // Type error
16821683
```
16831684

16841685
</details>

0 commit comments

Comments
 (0)