statelyai / xstate-tools

Public monorepo for XState tooling
183 stars 36 forks source link

[vscode extension] typegen incompatible with js files #309

Open eevman opened 1 year ago

eevman commented 1 year ago

vscode extension automatically inserts type assertion for tsTypes field in createMachine() for example from tsTypes: {}

we get

tsTypes: {} as import("./scan.machine.typegen").Typegen0

which is fine for typescript files. I have used this in javascript files (together with jsdoc to specify types) and it seems to work fine, however this automatic insertion in invalid for js files. I have actually used another editor to edit the file with this contents instead:

tsTypes: /** @type {import("./scan.machine.typegen").Typegen0} */ ({})

and after that I could get correct types for actions for example.

It would be nice if vscode extension could check if language of the file is javascript and insert corresponding jsdoc instead of using as keyword.

with-heart commented 1 year ago

I like that idea @eevman, I'll see if I can get that working