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 optional support to type. #668

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

colin-han
Copy link

@colin-han colin-han commented Oct 30, 2022

Based on the PR #654 , I'm trying to make a more readable solution to support optional properties of TypeScript.

const TypeA = t.type({
  propA: t.optional(t.string),
  propB: t.string
})

I define a new keyword t.optional to annotate a properties is optional. The above declaration will generated type likes following:

interface TypeA {
  propA?: string;
  propB: string;
}

I borrow all UT from the PR #654 . Thanks to the author @mjburghoffer, your UT help me so many.

BTW, I don't known why I cannot pass all test (prettier and eslint) on my local environment. If it's a problem to merge this PR. let me known, I will take more research for it.

@cchepelov
Copy link

This looks good!

What are the blockers for integration?

@colin-han
Copy link
Author

@cchepelov There still has some UT is not passed. And a newer version of TypeScript is required. I guess that is why this PR is not merged into master.

I'm sorry I have not enough time and skill to fix all issue. If the feature is required for you, you can use another library I published to NPM ( io-ts-with-optional ) as a workaround.

@cchepelov
Copy link

Thank you @colin-han!

I'll see if I can get away with no optionals for the time being. It looks like io-ts' 3.0 branch is moving a bit, too.
Afraid I'm lacking time/skill as well to help with a fix, although I'll sure be happy if that happens

@gcanti
Copy link
Owner

gcanti commented Dec 14, 2022

It looks like io-ts' 3.0 branch is moving a bit, too.

@cchepelov the active development of the next major iteration of io-ts (and more generally of the fp-ts ecosystem) is happening here

@colin-han
Copy link
Author

@gcanti It looks like the new Schema system is powerful. Do you have consider to support optional syntax like mine? The current optional syntax (C.struct({ a: C.string, b: C.number }, { c: C.boolean })) is a little less readable.

@gcanti
Copy link
Owner

gcanti commented Dec 15, 2022

@colin-han just landed in the development branch

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.

None yet

3 participants