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

[ts] make optional fields work if the key is ommited #660

Merged
merged 1 commit into from
Jan 1, 2025
Merged

Conversation

stopachka
Copy link
Contributor

Uri pointed out an issue in #459

If you have a messages entity like so:

messages: i.entity({
  content: i.string(),
  createdAt: i.date().optional(),
}),

Then using InstaQLEntity:

type CoreMessage = InstaQLEntity<AppSchema, "messages">;

const mWithOptionalFieldWorks: CoreMessage = { 
  id: '1', 
  content: 'hello',
};

You end up having an error, because typescript expects createdAt to be present, even though it's optional

Fix

I updated how we resolved attrs, so that instead of generating: createdAt: Foo | undefined, we generate: createdAt?: Foo | undefined

@nezaj @dwwoelfel @tonsky

Copy link

View Vercel preview at instant-www-js-ts1-jsv.vercel.app.

Copy link
Contributor

@nezaj nezaj left a comment

Choose a reason for hiding this comment

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

Nice!

@stopachka stopachka merged commit 90375c4 into main Jan 1, 2025
26 checks passed
@stopachka stopachka deleted the ts1 branch January 1, 2025 16:34
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