Closed lensbart closed 1 year ago
I have a hunch that the type of SerializeFrom
can’t be inferred because the package.json
of @remix-run/react
has "typings": "dist/index.d.ts"
, and that file doesn’t export SerializeFrom
Did you try wrapping your response in json
helper function?
It's not recommended to return pure JS objects
Did you try wrapping your response in
json
helper function?
The problem is with the underlying type of SerializeFrom
not being accessible. The type of loader
is correctly inferred in both cases:
() => { some: string; }
following the steps outlined above() => TypedResponse<{ some: string; }>
when the return value is wrapped in json
@lensbart Thanks for the tip about the underlying SerializeFrom
type. Looks like this is due to the fact that @remix-run/server-runtime
is a dev dependency. I've just opened a PR fixing this: https://github.com/remix-run/remix/pull/7137
@markdalgleish good to hear!
Semi-relatedly, I think it would be a good idea to upgrade the repository version of Yarn so that it imposes stricter rules on dependencies. (There have been several issues with Yarn that would have been caught by using Yarn 2 or higher.)
Closed by #7137
🤖 Hello there,
We just published version v0.0.0-nightly-65fdbcd-20230815
which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!
Thanks!
@markdalgleish I installed the nightly version (for all my remix dependencies), but this doesn’t seem to work. The behaviour is the same as before. Did you get a different result?
Thanks.
@lensbart The nightly version has fixed the initial issue where SerializeFrom
wasn't available, but I'm now getting a different issue where the type of data
is Record<string, number>
. SerializeFrom
internally uses Jsonify
from type-fest, and interestingly enough I was able to reproduce this issue even when using Jsonify
directly in a Yarn PnP project. I was able to reproduce this in the TS playground too:
Looks like this might be surfacing an upstream issue? Or am I missing something?
At this point I find it difficult to help, because it doesn’t match the issue I’m having (TypeScript being seemingly unable to “resolve” the underlying type of SerializeFrom
). Did you try exporting SerializeFrom
from the remix package that uses it?
I would also assume that the issue on the TypeScript playground is unrelated to Yarn PnP?
Could you share a minimal repo to make sure we're looking at the same thing?
I realise the TS playground is unrelated to Yarn PnP, but I was using it to try and see what the expected behaviour should be in a clean environment and was surprised to see a similar issue.
@markdalgleish Sure! Here you go: https://github.com/nextbook/serialize-from I just followed the steps in the first message in this issue (should it be reopened?). Let me know if I can provide any further information.
Cmd+click on useLoaderData
:
@lensbart Sorry, I meant with the nightly version.
@markdalgleish my bad. When I upgrade the remix dependencies to 0.0.0-nightly-65fdbcd-20230815
, I see the exact same thing as you described.
I’ll try to come up with a minimal reproduction for the issue I had earlier, after upgrading.
@markdalgleish Maybe I was confused and did something wrong when posting this message. Using the nightly seems to resolve my initial issue now. Apologies for any time lost.
I don’t have the issue with Record<string, number>
in my main repository, but not sure if that’s relevant since we have a reproduction already.
What version of Remix are you using?
1.19.1
Are all your remix dependencies & dev-dependencies using the same version?
Steps to Reproduce
yarn create remix
with default settings (my-remix-app
, Just the basics, Remix App Server, TypeScript, runyarn install
)cd my-remix-app
Make the following changes:
yarn set version berry
yarn
(you should see the message “automatically enabling the compatibility node-modules linker 👍”, a linenodeLinker: node-modules
will be added to.yarnrc.yml
)⇧ ⌘ P
on macOS) →TypeScript: Select TypeScript Version…
→Use Workspace Version
data
is still (correctly)SerializeObject<UndefinedToOptional<{ some: string; }>>
nodeLinker: node-modules
from.yarnrc.yml
(or change it tonodeLinker: pnp
) and runyarn
again. This will remove yournode_modules
folder and enable the Plug‘n’Play module resolution mechanismyarn dlx @yarnpkg/sdks vscode
data
is nowSerializeFrom<T>
.Cmd
+clicking onuseLoaderData
will go to line 114 incomponents.d.ts
:but it’s not possible to
Cmd
+click further onSerializeFrom
.Expected Behavior
The inferred type of
useLoaderData<typeof loader>()
remainsSerializeObject<UndefinedToOptional<{ some: string; }>>
as in step 7Actual Behavior
The inferred type of
useLoaderData<typeof loader>()
isSerializeFrom<T>
as described in step 11