Skip to content

Commit 01f406c

Browse files
[TS] Narrow types for Show utility (#701)
* Narrow types for Show utility * TIL that 0n is also falsy I don't know if I like that. 0n feels more object-y than 0 to me * Use NonNullable<T>. That's what TS type narrowing does by default. Downside: It won't correctly handle literal values like "hello" vs "", but oh well. * Add changeset --------- Co-authored-by: Jovi De Croock <[email protected]>
1 parent 5d3a42a commit 01f406c

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

.changeset/plenty-bikes-fold.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@preact/signals": patch
3+
---
4+
5+
Narrow types for Show utility, the callback is truthy by design

packages/preact/utils/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useMemo } from "preact/hooks";
66
interface ShowProps<T = boolean> {
77
when: Signal<T> | ReadonlySignal<T>;
88
fallback?: JSX.Element;
9-
children: JSX.Element | ((value: T) => JSX.Element);
9+
children: JSX.Element | ((value: NonNullable<T>) => JSX.Element);
1010
}
1111

1212
export function Show<T = boolean>(props: ShowProps<T>): JSX.Element | null {

0 commit comments

Comments
 (0)