-
Notifications
You must be signed in to change notification settings - Fork 13
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
chore: manage typescript at workspace root #36
Conversation
🦋 Changeset detectedLatest commit: 9ef1967 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -22,6 +23,7 @@ | |||
"lint-staged": "^13.2.2", | |||
"prettier": "^2.8.8", | |||
"sort-package-json": "^2.4.1", | |||
"turbo": "latest" | |||
"turbo": "latest", | |||
"typescript": "^5.1.3" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: cra-demo
still uses 4.7.4; to be upgraded in a follow-up PR
@@ -1,2 +0,0 @@ | |||
// @ts-nocheck |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is not referenced from anywhere.
@@ -1,6 +1,5 @@ | |||
import { Stripe } from '@stripe/stripe-js'; | |||
import { | |||
hasErrors, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused
|
||
FormspreeContext.displayName = 'Formspree'; | ||
|
||
let stripePromise: Promise<Stripe>; | ||
let stripePromise: Promise<Stripe | null>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix type: getStripe
returns Promise<Stripe | null>
}; | ||
|
||
if (props.stripePK) { | ||
getStripePromise(); | ||
getStripePromise(props.stripePK); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix type: need to pass the value after type narrowing
let stripe: Stripe | null; | ||
let elements: StripeElements | null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix type: the client getters for these return T | null
.
@@ -171,6 +168,7 @@ const useForm = ( | |||
: undefined, | |||
}) | |||
.then((result: SubmissionResponse) => { | |||
// @ts-ignore: unhandled result.response is possibly null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to fix as many type errors without changing the runtime behavior. It's impossible to fix these without changing the implementation to handle null
better. We'll do in a follow-up PR.
@@ -64,7 +64,7 @@ it('does not render anything if the field does not have an error', () => { | |||
{ | |||
field: 'name', | |||
message: 'is required', | |||
code: 'REQUIRED', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix type: correct the enums.
turbo.json
Outdated
"topo": { | ||
"dependsOn": ["^topo"] | ||
}, | ||
"typecheck": { | ||
"dependsOn": ["topo"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding topo
allows typecheck
tasks in formspree-core
and formspree-react
to run in parallel while ensuring that changing in formspree-core
will cause a cache miss in formspree-react
.
An alternative is to do: "typecheck": { "dependsOn": ["^typecheck"] }
but it'll cause formspree-react
to always run after formspree-core
.
@@ -1,4 +1,6 @@ | |||
{ | |||
"$schema": "https://turbo.build/schema.json", | |||
"globalDependencies": ["tsconfig.json"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the root tsconfig.json
changes, it should cause cache miss to the tasks.
This reverts commit 91aab65.
…e to the generate typedef
"declaration": true, | ||
"declarationDir": "dist/types", | ||
"noImplicitAny": true, | ||
"moduleResolution": "node", | ||
"declarationMap": true, | ||
"jsx": "react", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eventually, we should change this to react-jsx
: https://stackoverflow.com/questions/67776707/ts-config-jsx-reactjsx-vs-react.
However, it'll produce a breaking change (generated typedef will use JSX
type from react/runtime
instead).

@@ -1,17 +1,15 @@ | |||
{ | |||
"$schema": "https://json.schemastore.org/tsconfig", | |||
"display": "@formspree/react", | |||
"extends": ["../../tsconfig.json"], | |||
"compilerOptions": { | |||
"target": "es5", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be removed (i.e. to use root tsconfig
value for consistency between core and react packages) in the future. Since it will produce a very different built index.js
, we will update it as part of a breaking change release.
cc/ @colevscode
Might be worth a patch bump, if for no other reason, updates the changelog so we can track these improvements. To do that I suggest running |
Changes
tsconfig
to root and have package-specifictsconfig
extends it for consistencynull
andundefined
test
folderstypecheck
which runstsc
in typechecking modetypecheck
taskVerification
Checked the produced
index.d.ts
andindex.js
files and they're equivalent to the output produced on themain
branch.core/dist/index.d.ts
exact same outputcore/dist/index.js
equivalent output (seems like munged variable names are swapped but it produces the same result), note "use strict" is removedreact/dist/index.d.ts
exact same outputreact/dist/index.js
comparable output; expected the changes how we handlenull
andundefined
incontext.tsx
anduseForm.ts
.