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 MachineEvent.Factory.parse() method #91

Merged
merged 6 commits into from
Jan 25, 2024
Merged

Conversation

rkuhn
Copy link
Member

@rkuhn rkuhn commented Jan 25, 2024

No description provided.

@rkuhn rkuhn requested a review from Kelerchian January 25, 2024 10:30
@@ -68,7 +68,8 @@
"fast-equals": "^5.0.1",
"ts-node": "^10.9.1",
"typed-emitter": "^2.1.0",
"typescript": "^4.9.5"
"typescript": "^4.9.5",
"zod-validation-error": "^3.0.0"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, moving to optional

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you cannot set a dependency to optional AND import it. (import type is a different case)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then what is the purpose of optional: true? And what is the pattern for only optionally using a dependency?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In TypeScript it can be used with import type
In CJS Node code, including packages use require. with require you can do:

// optionally use some module
try {
  const module = require("somemodule")
  module.someFunction();
} catch (err) {}

/* eslint-disable @typescript-eslint/no-var-requires */

const ZOD = {
zod: (await import('zod').catch(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL await import can be used to export synchronously. Nice trick

@@ -31,11 +32,70 @@ export type MachineEvent<Key extends string, Payload extends object> = {
type: Key
} & Payload

type Zod = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be moved to zod.ts

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there are two zod.ts there would be the danger of divergence.

@rkuhn rkuhn merged commit 3f9b5b4 into master Jan 25, 2024
1 check passed
@rkuhn rkuhn deleted the rku/machine-event-parse branch January 25, 2024 18:00
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