-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test-d.ts
More file actions
23 lines (18 loc) · 781 Bytes
/
Copy pathindex.test-d.ts
File metadata and controls
23 lines (18 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { expectType } from "tsd";
import createContext, { type Context } from "./index.js";
// Create with default value
const stringContext = createContext("default");
expectType<Context<string>>(stringContext);
expectType<string>(stringContext.get());
// Run returns the function result
expectType<number>(stringContext.run("value", () => 42));
// RunWith returns a function wrapper
const result = stringContext.runWith<number>("scoped")(() => 42);
expectType<number>(result);
// Create without default
const numberContext = createContext<number>();
expectType<Context<number>>(numberContext);
expectType<number>(numberContext.get());
// Object context
const objectContext = createContext({ id: 0, name: "" });
expectType<{ id: number; name: string }>(objectContext.get());