Skip to content

Commit 77a0648

Browse files
committed
Update playground docs with 400+ types and examples
1 parent 7ac6444 commit 77a0648

2 files changed

Lines changed: 683 additions & 29 deletions

File tree

docs/playground.md

Lines changed: 342 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,363 @@ Try `uni-types` directly in your browser with real-time type checking!
1818
- 📦 **Pre-loaded Types** - All uni-types are available for import
1919
- 🎨 **Syntax Highlighting** - Full TypeScript syntax support
2020

21-
## Available Types
21+
## Available Types (400+)
2222

23-
All types from `uni-types` are available:
23+
All types from `uni-types` are available for import:
24+
25+
### Core Operations
2426

2527
```typescript
26-
// Core Operations
27-
import type { PickRequired, PickPartial, OmitRequired, OmitPartial } from 'uni-types'
28+
import type {
29+
PickRequired, PickPartial, OmitRequired, OmitPartial
30+
} from 'uni-types'
31+
```
2832

29-
// Tuple Operations
30-
import type { Head, Last, Tail, Init, Reverse, Flatten } from 'uni-types'
33+
### Tuple Operations
3134

32-
// Deep Operations
33-
import type { DeepPartial, DeepRequired, DeepReadonly, DeepMutable } from 'uni-types'
35+
```typescript
36+
import type {
37+
Head, Last, Tail, Init, Reverse, Flatten, TupleLength, IsEmptyTuple
38+
} from 'uni-types'
39+
```
3440

35-
// Type Guards
36-
import type { IsArray, IsTuple, IsEqual, IsAny, IsNever } from 'uni-types'
41+
### Deep Operations
3742

38-
// Brand Types
43+
```typescript
44+
import type {
45+
DeepPartial, DeepRequired, DeepReadonly, DeepMutable, DeepOmit, DeepPick
46+
} from 'uni-types'
47+
```
48+
49+
### Brand Types
50+
51+
```typescript
3952
import type { Brand, Unbrand } from 'uni-types'
53+
```
54+
55+
### Conditional Types
4056

41-
// Conditional Types
57+
```typescript
4258
import type { If, Not, And, Or } from 'uni-types'
59+
```
60+
61+
### Function Types
62+
63+
```typescript
64+
import type {
65+
Parameters, ReturnType, NthParameter, AsyncReturnType
66+
} from 'uni-types'
67+
```
68+
69+
### Key Utilities
70+
71+
```typescript
72+
import type {
73+
RenameKeys, PrefixKeys, SuffixKeys, KeysByValueType
74+
} from 'uni-types'
75+
```
76+
77+
### Numeric Types
78+
79+
```typescript
80+
import type { Inc, Dec, Add, Subtract, Range } from 'uni-types'
81+
```
82+
83+
### Path Utilities
84+
85+
```typescript
86+
import type {
87+
ValidPath, ArrayPaths, LeafPaths, PathLength
88+
} from 'uni-types'
89+
```
90+
91+
### Record Types
92+
93+
```typescript
94+
import type {
95+
DeepNullable, DeepOptional, Immutable, Mutable
96+
} from 'uni-types'
97+
```
98+
99+
### Template Literals
100+
101+
```typescript
102+
import type {
103+
ReplaceAll, Trim, StringLength, Repeat
104+
} from 'uni-types'
105+
```
106+
107+
### Type Guards
108+
109+
```typescript
110+
import type {
111+
IsArray, IsTuple, IsEqual, IsAny, IsNever, IsUnknown
112+
} from 'uni-types'
113+
```
114+
115+
### Type Inference
116+
117+
```typescript
118+
import type {
119+
Awaited, ArrayElement, ValueOf, FunctionKeys, NonFunctionKeys,
120+
FirstParameter, FunctionOnly, DataOnly
121+
} from 'uni-types'
122+
```
123+
124+
### Utility Types
125+
126+
```typescript
127+
import type {
128+
Merge, NonNullable, Exclusive, NoNullish, Nullable, Optional,
129+
Maybe, LoosePartial, AtLeastOne, StrictExtract, StrictExclude,
130+
UnionToIntersection, UnionToTuple
131+
} from 'uni-types'
132+
```
133+
134+
### Key Types
135+
136+
```typescript
137+
import type {
138+
RequiredKeys, OptionalKeys, WritableKeys, ReadonlyKeys
139+
} from 'uni-types'
140+
```
141+
142+
### Path Types
143+
144+
```typescript
145+
import type { Paths, PathValue, SplitPath } from 'uni-types'
146+
```
147+
148+
### String Case
149+
150+
```typescript
151+
import type {
152+
CamelCase, SnakeCase, CamelCaseKeys, SnakeCaseKeys
153+
} from 'uni-types'
154+
```
155+
156+
### Algorithms
157+
158+
```typescript
159+
import type {
160+
Sort, QuickSort, MergeSort, GCD, LCM, Factorial, Fibonacci, IsPrime,
161+
Find, FindIndex, Includes, IndexOf, LongestCommonPrefix,
162+
Reverse, Unique, Flatten, FlattenDeep, LevenshteinDistance
163+
} from 'uni-types'
164+
```
165+
166+
### Parsers
167+
168+
```typescript
169+
import type {
170+
ParseJSON, StringifyJSON, IsValidJSON, ParseURL, QueryParams, ParseCSV
171+
} from 'uni-types'
172+
```
173+
174+
### State Machines
175+
176+
```typescript
177+
import type { StateMachine, State, Transition } from 'uni-types'
178+
```
179+
180+
### Data Structures
181+
182+
```typescript
183+
import type {
184+
Tree, TreeNode, Graph, LinkedList, Stack, Queue
185+
} from 'uni-types'
186+
```
187+
188+
### HTTP & API
189+
190+
```typescript
191+
import type { HTTPMethod, HTTPStatus, Route, Middleware } from 'uni-types'
192+
```
193+
194+
### Database
195+
196+
```typescript
197+
import type { SQLType, QueryBuilder, Migration } from 'uni-types'
198+
```
199+
200+
### Concurrency
201+
202+
```typescript
203+
import type { Task, Pipeline, Scheduler, WorkerPool } from 'uni-types'
204+
```
205+
206+
### Interop
207+
208+
```typescript
209+
import type {
210+
ToTypeFest, ToTsToolbelt, IsCompatible
211+
} from 'uni-types'
212+
```
213+
214+
### Testing
215+
216+
```typescript
217+
import type {
218+
ExpectTrue, ExpectEqual, TypeCoverage, TypeComplexity
219+
} from 'uni-types'
220+
```
221+
222+
### Assertions
223+
224+
```typescript
225+
import type {
226+
AssertEqual, AssertExtends, AssertKeyof, AssertNotNil,
227+
RequireKeys, MakeOptional, RequireAtLeastOne, RequireExactlyOne,
228+
AssertHasProperty, RequireNotNullish, RequireArray, RequireFunction
229+
} from 'uni-types'
230+
```
231+
232+
### Async Utilities
233+
234+
```typescript
235+
import type {
236+
PromiseValue, PromiseResult, IsPromise, UnwrapPromise, WrapPromise,
237+
PromiseSettledResult
238+
} from 'uni-types'
239+
```
240+
241+
### Collection Types
242+
243+
```typescript
244+
import type {
245+
TypeSet, SetAdd, SetRemove, SetHas, SetUnion, SetIntersection,
246+
SetDifference, SetIsEmpty, SetIsSubset,
247+
TypeMap, MapGet, MapSet, MapHas, MapDelete, MapKeys, MapValues,
248+
ListLength, ListReverse, ListConcat, ListFilter, ListFind, ListIncludes
249+
} from 'uni-types'
250+
```
251+
252+
### Object Operations
253+
254+
```typescript
255+
import type {
256+
ObjectMap, ObjectFilter, ObjectPickByType, ObjectOmitByType, ObjectInvert,
257+
DeepMerge, DeepAssign, DeepDefaults,
258+
HasProperty, HasProperties, HasMethod
259+
} from 'uni-types'
260+
```
261+
262+
### Pattern Matching
263+
264+
```typescript
265+
import type {
266+
Match, Case, Default, TypeFilter, TypeFind, TypeIncludes
267+
} from 'uni-types'
268+
```
269+
270+
### String Operations
271+
272+
```typescript
273+
import type {
274+
Split, Join, KebabCase, PascalCase, IsEmail, IsUUID, IsURL, Chunk
275+
} from 'uni-types'
276+
```
277+
278+
### Performance
279+
280+
```typescript
281+
import type {
282+
Simplify, DeepSimplify, Cached, CachedValue, Memoized,
283+
Lazy, ForceEvaluate, Deferred, FlattenType,
284+
StripNever, StripUndefined, Compact
285+
} from 'uni-types'
286+
```
287+
288+
### Schema Validation
289+
290+
```typescript
291+
import type {
292+
RuntimeGuard, GuardedType, HasRuntimeCheck, CompositeGuard,
293+
ZodOutput, ZodInput, IsZodSchema, ZodShape, ZodArrayElement,
294+
YupOutput, YupInput, IsYupSchema
295+
} from 'uni-types'
296+
```
297+
298+
### Ecosystem Integration
299+
300+
```typescript
301+
import type {
302+
ComponentProps, PropsWithChildren, PrismaCreateInput
303+
} from 'uni-types'
304+
```
305+
306+
## Example Code
307+
308+
Here's a comprehensive example showcasing various features:
309+
310+
```typescript
311+
import type {
312+
PickRequired, DeepPartial, DeepReadonly, Sort, GCD, Factorial,
313+
IsArray, IsTuple, IsEqual, ObjectPickByType, Split, Join,
314+
CamelCase, SnakeCase, Paths, PathValue, AssertEqual
315+
} from 'uni-types'
316+
317+
// Core operations - make properties required
318+
interface User {
319+
name?: string
320+
age?: number
321+
email: string
322+
}
323+
type RequiredUser = PickRequired<User, 'name' | 'age'>
324+
325+
// Deep operations - nested partials
326+
interface Config {
327+
database: {
328+
host: string
329+
port: number
330+
credentials: {
331+
user: string
332+
password: string
333+
}
334+
}
335+
}
336+
type PartialConfig = DeepPartial<Config>
337+
338+
// Type-level algorithms
339+
type SortedNumbers = Sort<[3, 1, 4, 1, 5, 9, 2, 6]>
340+
type GcdResult = GCD<48, 18>
341+
type FactorialResult = Factorial<5>
342+
343+
// Type guards
344+
type ArrayCheck = IsArray<string[]>
345+
type TupleCheck = IsTuple<[1, 2, 3]>
346+
type EqualCheck = IsEqual<string, string>
347+
348+
// Object operations - pick by type
349+
interface MixedObject {
350+
name: string
351+
count: number
352+
active: boolean
353+
callback: () => void
354+
}
355+
type OnlyStrings = ObjectPickByType<MixedObject, string>
356+
type OnlyNumbers = ObjectPickByType<MixedObject, number>
357+
358+
// String operations
359+
type SplitResult = Split<'a-b-c', '-'>
360+
type JoinResult = Join<['a', 'b', 'c'], '-'>
361+
type CamelResult = CamelCase<'hello-world'>
362+
type SnakeResult = SnakeCase<'helloWorld'>
363+
364+
// Path utilities
365+
type AllPaths = Paths<{ a: { b: { c: string } } }>
366+
type ValueAtPath = PathValue<{ a: { b: { c: string } } }, 'a.b.c'>
43367

44-
// Performance
45-
import type { Simplify, DeepSimplify, Compact } from 'uni-types'
368+
// Type assertions - compile-time validation
369+
type TestAssertion = AssertEqual<string, string> // string
370+
type TestAssertion2 = AssertEqual<string, number> // never
46371

47-
// And many more...
372+
// Verify factorial
373+
type VerifyFactorial = AssertEqual<Factorial<5>, 120>
48374
```
49375
50376
## External Resources
51377
52378
- [TypeScript Playground](https://www.typescriptlang.org/play) - Official TypeScript playground
53379
- [Type Challenges](https://github.com/type-challenges/type-challenges) - Practice TypeScript type challenges
380+
- [type-fest](https://github.com/sindresorhus/type-fest) - Popular TypeScript type collection

0 commit comments

Comments
 (0)