-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
V2 issue: inferred type disappearing #7246
Comments
I've pushed a repo that reproduces this error: https://github.com/kentcdodds/remix-issue-7246/blob/eed5d5695b4ec89786db4af3b801ee4a49cedcc1/app/routes/test.tsx#L11 |
I also added a GitHub workflow. There's another TS issue in there as well (#7239), but you'll find the ts issue here: https://github.com/kentcdodds/remix-issue-7246/actions/runs/5958895147/job/16163804680#step:4:24 |
The Jsonify utility used by Remix will make a `Record<string, any>` disappear in the type: remix-run/remix#7246 But considering this further, "unknown" is a safer option for this type anyway because it avoids issues with accidentally accessing the values off the submission payload without first checking them. So I do think this change should be made.
This is an issue with using type-fest's Jsonify which is the real culprit. Here's a TS Playground. I'm not sure whether to consider this a bug though. It feels like a bug to me... I guess they treat |
This has been accepted by Sindre: sindresorhus/type-fest#667 Someone smart at TS could probably fix it pretty quick. |
I did my best, but I couldn't get it to work: sindresorhus/type-fest#668 |
Maybe related: #6994 |
The Jsonify utility used by Remix will make a `Record<string, any>` disappear in the type: remix-run/remix#7246 But considering this further, "unknown" is a safer option for this type anyway because it avoids issues with accidentally accessing the values off the submission payload without first checking them. So I do think this change should be made.
The Jsonify utility used by Remix will make a `Record<string, any>` disappear in the type: remix-run/remix#7246 But considering this further, "unknown" is a safer option for this type anyway because it avoids issues with accidentally accessing the values off the submission payload without first checking them. So I do think this change should be made.
Maybe I'm missing something here, but If you want a type to survive the network/JSON boundary, it must not be or include |
I just stumbled across this same issue in a few locations after my upgrade, so just wanted to drop a note on one thing I noticed, whether it's relevant or not. Passing a promise through It's kind of a seperate thing but I feel like returning a promise via json should result in a type error 👀 Such an easy thing to accidentally do |
Same for us. This error also prevents us from upgrading our projects to |
Here's another repl for what I believe to be the same issue. import { json } from '@remix-run/node';
import { useLoaderData } from '@remix-run/react';
import { Schema } from '@cfworker/json-schema';
export function loader() {
const schema = {} as Schema | null;
return json({ schema });
}
export default function Page() {
const { schema } = useLoaderData<typeof loader>();
// ^ Property 'schema' does not exist on type 'JsonifyObject<{}>'.
return JSON.stringify(schema);
} Playground Link: Provided |
Tracked this down to this line in [(...arguments_: any[]) => any] extends [Type[Key]] ? never : Key; The Here's a minimal example with a suggested fix for |
For the |
Is there a temporary workaround for this error? |
The temporary issue seems to be using patch-package to revert #6642 Patch package here: https://gist.github.com/smeijer/885310fca21828272bca29097f490534 |
Any updates on this issue? I can't upgrade my project to v2 with TS errors everywhere |
|
Hi same issue here, I don't quite understand how to implement this:
|
Ok after some fiddling I made it work, the key is using: |
It's a patch-package patch, not a git patch. |
Fixed by #7605 . You can try it out with the next nightly release (which will get published in a few hours as of the time writing this comment). |
Hooray! Thank you! |
All nightly packages installed and fix is confirmed you are amazing @pcattori! |
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
* Update Remix versions to 2.0.0-pre.3 * Fix types in Hydrogen * Fix type exports in Oxygen adapter * Mock v2 flags in CLI * Rename V2_MetaFunction type in skeleton * Remove CSS nesting to avoid ESBuild warnings * Remove old error and catch boundaries * Add small wrapper for root data to fix type unknown * ts-ignore jsonify errors remix-run/remix#7246 * Remove vs flags from template * Update to Remix 2.0.0 * Update skeleton types to v2 * Update hello-world types to v2 * Update demo-store types to v2 * Update examples types to v2 * Remove future v2 flags * Minor type update * Remove v2 flags from CLI * Remix deprecated tsconfig in config * Fix typecheck * Stop injecting booleans in remix config. Fix tests * Package lock * Fix types * Remove unused tests * Cleanup * Update package-lock * Update Remix versions to latest nightly * Fix optimistic-ui for Remix v2 * Update package-lock * Remove ts-ignore comments related to JsonifyObject error * Add missing reference to eslint package in skeleton * Update to Remix 2.1.0 * Fix SerializeFrom in JSDoc * Fix typedefs in JSDoc * Use SerializeFrom in demo-store * Changesets * Support generics in JSDoc * Set Remix as a non-pinned peer dependency * Changesets * Update .changeset/smart-ways-destroy.md Co-authored-by: Bret Little <[email protected]> * Remove react dep again * Remove template guidelines for Remix v1 * Minor fix * Update changeset --------- Co-authored-by: Bret Little <[email protected]>
I'm seeing this issue again with 2.4.0. Workaround is to do a hard cast to the type you need: const actionResult = useActionData<typeof action>();
const errors = actionResult.formResult as MyType; |
Could you open a new issue with a reproduction? Both reproductions in this issue are working OK for me in 2.4.0: TS Playground |
@brophdawg11 thank you for the link, I have played a little with your example and my own use case and it seems that it just doesn't like descructuring. When I do this const { schema } = data2;
const { key } = data2.schema;
So is it expected behavior for destructuring to work or am I just too much of a remix noob? |
@AndrewOt, looks like the thing it's got a problem with destructuring is the fact that the schema could be null. Can't destructure null. You'll have to do a null-check first |
Ah. Right. It would seem I had a JS noob moment. Thanks @kentcdodds! |
* Update Remix versions to 2.0.0-pre.3 * Fix types in Hydrogen * Fix type exports in Oxygen adapter * Mock v2 flags in CLI * Rename V2_MetaFunction type in skeleton * Remove CSS nesting to avoid ESBuild warnings * Remove old error and catch boundaries * Add small wrapper for root data to fix type unknown * ts-ignore jsonify errors remix-run/remix#7246 * Remove vs flags from template * Update to Remix 2.0.0 * Update skeleton types to v2 * Update hello-world types to v2 * Update demo-store types to v2 * Update examples types to v2 * Remove future v2 flags * Minor type update * Remove v2 flags from CLI * Remix deprecated tsconfig in config * Fix typecheck * Stop injecting booleans in remix config. Fix tests * Package lock * Fix types * Remove unused tests * Cleanup * Update package-lock * Update Remix versions to latest nightly * Fix optimistic-ui for Remix v2 * Update package-lock * Remove ts-ignore comments related to JsonifyObject error * Add missing reference to eslint package in skeleton * Update to Remix 2.1.0 * Fix SerializeFrom in JSDoc * Fix typedefs in JSDoc * Use SerializeFrom in demo-store * Changesets * Support generics in JSDoc * Set Remix as a non-pinned peer dependency * Changesets * Update .changeset/smart-ways-destroy.md Co-authored-by: Bret Little <[email protected]> * Remove react dep again * Remove template guidelines for Remix v1 * Minor fix * Update changeset --------- Co-authored-by: Bret Little <[email protected]>
What version of Remix are you using?
0.0.0-nightly-49e8da1-20230823
Are all your remix dependencies & dev-dependencies using the same version?
Steps to Reproduce
I can't get this to reproduce in the TypeScript Playground for some reason, but here's that
Interestingly there's a difference in the type on the TS Playground and my local version:
I also tried this out on a fresh project, so I'm confident it's not just my project.
Expected Behavior
I expect to be able to infer types of
Record<string, any>
Actual Behavior
That property disappears.
The text was updated successfully, but these errors were encountered: