Skip to content

Commit 9570afa

Browse files
committed
🎉 give examples
1 parent 0fd303c commit 9570afa

5 files changed

Lines changed: 12 additions & 8 deletions

File tree

example/01_preact/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"devDependencies": {
1515
"@preact/preset-vite": "^2.3.0",
16-
"assert-util-types": "0.0.5",
16+
"assert-util-types": "0.0.7",
1717
"typescript": "^4.6.4",
1818
"vite": "^3.0.7"
1919
}

example/01_preact/pnpm-lock.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/01_preact/src/app.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function asToDoId(value: unknown): TodoId {
1818
return value;
1919
}
2020

21-
export function App() {
21+
export function App(): JSX.Element {
2222
const { data, error } = useTodoFetch<Todo>(asToDoId('1'));
2323
if (error) return <p>There is an error.</p>
2424
if (!data) return <p>Loading...</p>

example/01_preact/src/use-todo-fetch.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useEffect, useReducer, useRef } from 'preact/hooks'
2+
import { assertMatchedType } from 'assert-util-types';
23
import type { TodoId } from './type'
34

45
interface State<T> {
@@ -64,7 +65,10 @@ export function useTodoFetch<T = unknown>(id: TodoId, options?: RequestInit): St
6465
throw new Error(response.statusText)
6566
}
6667

67-
const data = (await response.json()) as T
68+
const data: T = await response.json();
69+
70+
// if hav specified props, return the data
71+
assertMatchedType<{ data: T }>(data, ['data']);
6872
cache.current[url] = data
6973
if (cancelRequest.current) return
7074

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "assert-util-types",
3-
"version": "0.0.6",
3+
"version": "0.0.7",
44
"description": "daily work would be much easier if there were utility assert functions",
55
"scripts": {
66
"dev": "vite",

0 commit comments

Comments
 (0)