Skip to content

Bug: [5.25.0] typing issue when using assertEvent and generics #5448

@jlowcs

Description

@jlowcs

XState version

XState version 5

Description

function test(event: InspectionEvent) {
	assertEvent(event, '@xstate.event');
	// eslint-disable-next-line no-console
	console.log(event.event);
}

function test2<TEVENT extends InspectionEvent>(event: TEVENT) {
	assertEvent(event, '@xstate.event');
	// eslint-disable-next-line no-console
	console.log(event.event);
}

test2 results in a type error:
Image

Expected result

no error, asserts works as expected

Actual result

error, cannot use assertEvent with generics.

Reproduction

https://codesandbox.io/p/devbox/nifty-cloud-wnzqnr

Additional context

I was able to avoid the typing issue by doing this, but I'm not sure if there's a better option:

function test2<TEVENT extends InspectionEvent>(eventP: TEVENT) {
	const event: InspectionEvent = eventP;
	assertEvent(event, '@xstate.event');
	// eslint-disable-next-line no-console
	console.log(event.event);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions