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

fix optional types #4

Merged
merged 4 commits into from
Jan 6, 2025
Merged

fix optional types #4

merged 4 commits into from
Jan 6, 2025

Conversation

natew
Copy link
Contributor

@natew natew commented Jan 5, 2025

No description provided.

@0xcadams
Copy link
Contributor

0xcadams commented Jan 5, 2025

Hey @natew, could you give me more context here so we can make sure this is fixed? The reason these types are this way is because the optional field is typed as boolean here, as opposed to keeping the type of the input.

https://github.com/rocicorp/mono/blob/85e3f0ee820609b8f6945e55c043b9ed55a9908a/packages/zero-schema/src/column.ts#L1

e.g. something like:

export function string<T extends string = string, O extends boolean = false>(optional: O = false) {
  return {
    type: 'string',
    optional,
    customType: null as unknown as T,
  } as const;
}

@natew
Copy link
Contributor Author

natew commented Jan 6, 2025

You want it to be inferred. That way it matches the notNull. I went further and had it be optional also if there’s a default value which is correct too, as it matches what your database expects. It works perfectly on my schema I can link it when I get home later.

@0xcadams
Copy link
Contributor

0xcadams commented Jan 6, 2025

Sounds great - related PR here and I will update tests here and merge - thanks!

rocicorp/mono#3474

Copy link
Contributor

@0xcadams 0xcadams left a comment

Choose a reason for hiding this comment

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

Added some other changes I've been working on - thanks!

@0xcadams 0xcadams enabled auto-merge January 6, 2025 02:52
@0xcadams 0xcadams merged commit b0f46f4 into BriefHQ:main Jan 6, 2025
2 checks passed
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