Skip to content

Commit 553bde3

Browse files
chore: add typescript usage example
1 parent d32f86e commit 553bde3

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { is } from '../lib/is.object';
2+
3+
// Example usage with the problem
4+
interface Config {
5+
a?: string;
6+
b?: string;
7+
}
8+
const config: Config = {
9+
a: 'x',
10+
b: 'y'
11+
};
12+
13+
function configFunction(value: string): string {
14+
return '';
15+
}
16+
17+
// Cause typescript returns `boolean` this will generate a type error
18+
if (is.not.undefined(config.a)) {
19+
configFunction(config.a);
20+
}
21+
22+
// Cause typescript return `value is undefined` will not generate an error
23+
if (!is.undefined(config.a)) {
24+
configFunction(config.a);
25+
}

0 commit comments

Comments
 (0)