Wrong typings generated when importing types from a package in a Rush monorepo (PNPM hard links)
See original GitHub issueCurrent Behavior
I run tsdx build --transpileOnly
From this source
import { useToast as useChakraToast } from '@chakra-ui/react'
import { useMemo } from 'react'
import type { UseToastOptions } from '@chakra-ui/react'
export const useToast = (options?: UseToastOptions) => {
const defaultOptions = useMemo(() => {
return {
position: 'top-right' as UseToastOptions['position'],
status: 'success' as UseToastOptions['status'],
isClosable: true,
...(options ?? {}),
}
}, [options])
return useChakraToast(defaultOptions)
}
It generates this d.ts:
export declare const useToast: (options?: any) => any;
Expected behavior
Should output (and this is what regular tsc
with emitDeclarationsOnly
does):
import type { UseToastOptions } from '@chakra-ui/react';
export declare const useToast: (options?: UseToastOptions | undefined) => {
(options?: UseToastOptions | undefined): string | number | undefined;
close: (id: string | number) => void;
closeAll: (options?: import("@chakra-ui/react").CloseAllToastsOptions | undefined) => void;
update(id: string | number, options: Pick<UseToastOptions, "status" | "render" | "position" | "duration" | "onCloseComplete" | "title" | "description" | "isClosable" | "variant">): void;
isActive: (id: string | number) => boolean | undefined;
};
Additional context
It’s Rush.js managed monorepo so it uses PNPM so hard links to link modules into node_modules
.
I’m using TS 4. A similar workaround mentioned here https://github.com/formium/tsdx/issues/926 (using PNPM fashioned resolutions) is applied.
If built without --transpileOnly
fails with
app-frontend/libraries/hooks/common/src/useToast.ts(1,10): semantic error TS2305: Module '"../node_modules/@chakra-ui/react/dist/types"' has no exported member 'useToast'.
Your environment
System:
OS: Linux 5.3 Ubuntu 20.04.1 LTS (Focal Fossa)
CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor
Memory: 449.17 MB / 31.37 GB
Container: Yes
Shell: 5.8 - /usr/bin/zsh
Binaries:
Node: 14.15.4 - ~/.nvm/versions/node/v14.15.4/bin/node
Yarn: 1.22.10 - ~/.nvm/versions/node/v14.15.4/bin/yarn
npm: 6.14.10 - ~/.nvm/versions/node/v14.15.4/bin/npm
Browsers:
Chrome: 87.0.4280.88
Firefox: 85.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:12
Top Results From Across the Web
rushstack/rushstack - Gitter
I use the default setup, I just added projects in rush.json and execute rush update, the only problem is it doesnt download all...
Read more >Workspace | pnpm
Workspace. pnpm has built-in support for monorepositories (AKA multi-package repositories, multi-project repositories, or monolithic repositories).
Read more >PyCharm 2020.3.1 Release Notes | Knowledge Base
Bug, PY-45263, Wrong type error when exists warning "Package requirement ... is ... indexing hard links - used by pnpm & @Vladimirs Garins/rush...
Read more >Rush.js - Monorepo managment tool for JS/TS ... - YouTube
In half an hour I'll explain what Rush.js is, the overview of its basic features, few examples, the philosophy behind a few of...
Read more >Monorepos in JavaScript and TypeScript - Hacker News
I had an extraordinarily hard time getting a monorepo set up for a proof of ... and 3) watch said backend schema and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For reference, I am fairly sure I fixed this upstream in https://github.com/ezolenko/rollup-plugin-typescript2/pull/332, which fixed https://github.com/ezolenko/rollup-plugin-typescript2/issues/330, which is a very similar upstream issue with
pnpm
symlinks.To use that in your project, you can set your
pnpm
overrides
to userollup-plugin-typescript2
0.32.0+:And indeed, while the issue is different here, the root cause is the same as #953 so they are effectively duplicates.
No, I meant a different Rollup TypeScript plugin. They all have their own issues however and I was already contributing to rpt2 a bit in the past to fix issues from TSDX. I found rpt2 to be the simplest to contribute to by a wide margin, so I actually recently stepped up to help maintain it and have fixed a ton of issues in the past month, including the most long-standing ones like this one with
pnpm
symlinks. Can see https://github.com/ezolenko/rollup-plugin-typescript2/issues/234#issuecomment-1139202740 for more details on that (and a root cause analysis on this and why TypeScript integrations are difficult to implement due to TS having a sparsely documented API).@agilgur5 thank you for your work! I’m no longer working on this codebase to try, but still. Tsdx is my tool to go, so I’m happy it’s probably fixed now.