Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add TagsFrom helper type #3835

Merged
merged 5 commits into from
Feb 18, 2023
Merged

add TagsFrom helper type #3835

merged 5 commits into from
Feb 18, 2023

Conversation

with-heart
Copy link
Contributor

@with-heart with-heart commented Feb 15, 2023

Hi yall! I saw a helper type request on Discord today that seemed easy enough to implement: TagsFrom

TagsFrom allows us to access the typegen tags type of a Machine State, or Interpreter:

import { TagsFrom } from "xstate";

const machine = createMachine({
  tsTypes: {} as {
    "@@xstate/typegen": true;
    tags: "a" | "b" | "c";
  }
});

type Tags = TagsFrom<typeof machine>; // 'a' | 'b' | 'c'

If typegen isn't enabled, TagsFrom returns string (which matches hasTag):

import { TagsFrom } from "xstate";

const machine = createMachine({});

type Tags = TagsFrom<typeof machine>; // string

@changeset-bot
Copy link

changeset-bot bot commented Feb 15, 2023

🦋 Changeset detected

Latest commit: 38dea6d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
xstate Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ghost
Copy link

ghost commented Feb 15, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 15, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 38dea6d:

Sandbox Source
XState Example Template Configuration
XState React Template Configuration

@with-heart
Copy link
Contributor Author

with-heart commented Feb 15, 2023

How do you feel about the tests for this @Andarist?

Edit: Ugh I just noticed that @ts-expect-error covers both actual type errors and syntax warnings like unused vars. Didn't realize that and makes the types tests kind of awkward imo.

@with-heart
Copy link
Contributor Author

Ugh, we should achieve formatting parity with xstate-tools bc I keep forgetting that imports aren't managed automatically like they are over there 😭

@Andarist
Copy link
Member

Ugh, we should achieve formatting parity with xstate-tools bc I keep forgetting that imports aren't managed automatically like they are over there 😭

yeah, the situation is unfortunate - but we don't want to enable things like this at the moment here to avoid unnecessary merge conflicts when merging main to next

@with-heart
Copy link
Contributor Author

@Andarist makes perfect sense. nice changes, appreciate it!

@Andarist Andarist merged commit 4314720 into statelyai:main Feb 18, 2023
@github-actions github-actions bot mentioned this pull request Feb 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants