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

@redwoodjs/forms: Convert to TS #1431

Merged
merged 1 commit into from
Nov 4, 2020
Merged

Conversation

Tobbe
Copy link
Member

@Tobbe Tobbe commented Nov 3, 2020

I have some TODOs left in the code that I need to clear up

@Tobbe Tobbe marked this pull request as draft November 3, 2020 14:04
@Tobbe Tobbe force-pushed the tobbe-ts-forms branch 4 times, most recently from 07e414c to 50cdd57 Compare November 3, 2020 15:08
packages/forms/src/index.tsx Outdated Show resolved Hide resolved
@Tobbe Tobbe force-pushed the tobbe-ts-forms branch 2 times, most recently from ded0faf to 8c3eb2d Compare November 4, 2020 09:24
@Tobbe Tobbe changed the title WIP: @redwoodjs/forms: Convert to TS @redwoodjs/forms: Convert to TS Nov 4, 2020
@Tobbe
Copy link
Member Author

Tobbe commented Nov 4, 2020

image

Tried it with the form from the tutorial. Still works like it's supposed to.

@Tobbe Tobbe marked this pull request as ready for review November 4, 2020 09:26
@Tobbe
Copy link
Member Author

Tobbe commented Nov 4, 2020

@peterp Ready for review!

Copy link
Contributor

@peterp peterp left a comment

Choose a reason for hiding this comment

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

I'm not a TS expert, by any measure, I'm still trying to get my head around conditional generics, but I've made two suggestions.

setCoercions: React.Dispatch<React.SetStateAction<Coercions>>
}

const CoercionContext = React.createContext({} as CoercionContextInterface)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we don't have default values for this context, we can do something like this:

React.createContext<Partial<CoercionContext>>({});

https://fettblog.eu/typescript-react/context/#context-without-default-values

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't want to do this. It's effectively make all attributes of the context optional, which I don't want. We actually do have kind of "default values". They're just not set here. They're set further down as props to the Provider. Whatever you put here is never going to be used. It's only for when you use the context outside of its Provider, which we never do.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's fair. We're not trying to satisfy TS here... but rather our intention.

packages/forms/src/coercion.tsx Outdated Show resolved Hide resolved
@peterp
Copy link
Contributor

peterp commented Nov 4, 2020

@Tobbe This is great, thanks!

@peterp peterp added this to the Next release milestone Nov 4, 2020
@peterp peterp merged commit 3150066 into redwoodjs:main Nov 4, 2020
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.

3 participants