inferred type of '...' cannot be named without a reference to '...'

I found this in an old question from about a year ago when running into this issue in the process of adding type safety to Waku (new react framework by dai-shi) link to error I plan to use type annotation to unblock this per the recommendation here I wanted to re-ask this though, in case anyone here has come across a better way to fix this issue with a pnpm project over the course of the past year. @ArkDavid is this still something you see from time to time? Edit: Maybe this question is better suited for twitter?
14 Replies
tylersayshi
tylersayshiOP4mo ago
Disregard this ^ I just read to the helpful comment in that ts thread 🤦‍♂️ https://github.com/microsoft/TypeScript/issues/42873#issuecomment-2065572017
GitHub
The inferred type of "X" cannot be named without a reference to "Y"...
Bug Report 🔎 Search Terms inferred type cannot be named, symlink node_modules 🕗 Version & Regression Information I'm verifying the problem on the [email protected]. I've not tried older ...
ssalbdivad
ssalbdivad4mo ago
Would be interested to know what the specific error you got was
tylersayshi
tylersayshiOP4mo ago
It shows in this failed CI job here: https://github.com/dai-shi/waku/actions/runs/10761950734/job/29841704519?pr=854
Error: e2e/fixtures/render-type/src/entries.tsx(6,1): error TS2742: The inferred type of 'default' cannot be named without a reference to '../node_modules/waku/dist/router/common.js'. This is likely not portable. A type annotation is necessary.
Error: e2e/fixtures/render-type/src/entries.tsx(6,1): error TS2742: The inferred type of 'default' cannot be named without a reference to '../node_modules/waku/dist/router/common.js'. This is likely not portable. A type annotation is necessary.
ssalbdivad
ssalbdivad4mo ago
Is this related to ArkType or just a general TS question?
tylersayshi
tylersayshiOP4mo ago
general ts question... sorry. I kinda just figured this would be a good place to check for an error as weird as this one 😅
ssalbdivad
ssalbdivad4mo ago
Ahh okay yeah I've dealt with this also so I just wanted to make sure it wasn't something new internally. Generally https://discord.com/channels/957797212103016458/1114601623285678192 is probably a good place to ask broader TS questions, although not a big deal at all. You just had me worried for a sec 😛
tylersayshi
tylersayshiOP4mo ago
haha sorry for the scare! definitely good to know that for the future. I appreciate you taking a minute to respond here too 🙂
ssalbdivad
ssalbdivad4mo ago
No problem! Happy to help Well I didn't really help TBH lol But if I can I will 😛
tylersayshi
tylersayshiOP4mo ago
Your old message did! haha I just didn't read it closely enough the first time
ssalbdivad
ssalbdivad4mo ago
Oh good! I didn't realize you were linking to an old answer of mine haha
tylersayshi
tylersayshiOP4mo ago
yep! it was re-assuring to see that as validation that I wasn't mis-configuring something and seems to be a somewhat known issue.
PIat
PIat4mo ago
Hi, so how did you fix it in the end? For me I did export * from 'arktype' in that package's type file, but that makes it very slow to build
tylersayshi
tylersayshiOP4mo ago
This was the file where the error was occuring. It seems like this will be an internal issue only from what I can tell, so I just added the type annotation as was recommended by that github issue and the error message. It's neat to know that export * could also work, but it definitely does sound slower than I'd like.
diff --git a/e2e/fixtures/render-type/src/entries.tsx b/e2e/fixtures/render-type/src/entries.tsx
index 06a6bd1..cee13f2 100644
--- a/e2e/fixtures/render-type/src/entries.tsx
+++ b/e2e/fixtures/render-type/src/entries.tsx
@@ -3,27 +3,33 @@ import { createPages } from 'waku/router/server';
import { ServerEcho } from './ServerEcho.js';
import { ClientEcho } from './ClientEcho.js';

-export default createPages(async ({ createPage }) => [
- ...
-]);
+// This needs type annotations for the return type of createPages
+// @see https://github.com/microsoft/TypeScript/issues/42873#issuecomment-2065572017
+const router: ReturnType<typeof createPages> = createPages(
+ async ({ createPage }) => [
+ ...
+ ],
+);
+
+export default router;
diff --git a/e2e/fixtures/render-type/src/entries.tsx b/e2e/fixtures/render-type/src/entries.tsx
index 06a6bd1..cee13f2 100644
--- a/e2e/fixtures/render-type/src/entries.tsx
+++ b/e2e/fixtures/render-type/src/entries.tsx
@@ -3,27 +3,33 @@ import { createPages } from 'waku/router/server';
import { ServerEcho } from './ServerEcho.js';
import { ClientEcho } from './ClientEcho.js';

-export default createPages(async ({ createPage }) => [
- ...
-]);
+// This needs type annotations for the return type of createPages
+// @see https://github.com/microsoft/TypeScript/issues/42873#issuecomment-2065572017
+const router: ReturnType<typeof createPages> = createPages(
+ async ({ createPage }) => [
+ ...
+ ],
+);
+
+export default router;
tylersayshi
tylersayshiOP4mo ago
It seems worth mentioning that this widens the type of router in this case. In other cases I use the inference to collect the types of the paths created from the results of createPage which get returned in a list from createPages: example source code So for this file where I annotated the type of router, I lose that inference and my paths for it have to just revert to any string. In this case that is acceptable, but if this came up after publishing the types to an end user of the library I would need to find a better fix. afaict though, this is just related to pnpm linking within the scope of the monorepo I am developing in, so it shouldn't be in issue after publishing.
No description
No description
Want results from more Discord servers?
Add your server