Skip to content

Commit

Permalink
Added t() to allow for simpler use of schema
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpocock committed Jan 25, 2022
1 parent 9b419a8 commit 3252065
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
16 changes: 16 additions & 0 deletions .changeset/serious-snails-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'xstate': patch
---

Added `t()`, which can be used to provide types for `schema` attributes in machine configs:

```ts
import { t, createMachine } from 'xstate';

const machine = createMachine({
schema: {
context: t<{ value: number }>(),
events: t<{ type: 'EVENT_1' } | { type: 'EVENT_2' }>()
}
});
```
5 changes: 3 additions & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
InterpreterStatus
} from './interpreter';
import { matchState } from './match';
import { createSchema } from './schema';
import { createSchema, t } from './schema';

const actions = {
raise,
Expand Down Expand Up @@ -73,7 +73,8 @@ export {
spawn,
doneInvoke,
createMachine,
createSchema
createSchema,
t
};

export * from './types';
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/schema.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export function createSchema<T>(schema?: any): T {
return schema as T;
}
export const t = createSchema;

0 comments on commit 3252065

Please sign in to comment.