Material UI - چرا تایپاسکریپت هنگام استفاده از pnpm خطا میدهد؟
من در تلاش هستم از yarn به pnpm مهاجرت کنم، اما با یک مشکل کوچک روبرو شدهام و مطمئن نیستم چگونه باید با آن برخورد کنم. هنوز تنظیمات مربوط به hoisting را تغییر ندادهام (ترجیح میدهم اگر ممکن است این کار را نکنم)، اما سعی دارم بفهمم چرا این برایم مشکل ایجاد میکند.
من یک تابع کمکی کوچک دارم که هنگام استفاده از yarn به خوبی کار میکند:
import { makeStyles } from '@material-ui/core';
export const useAlertConfigurationNameStyles = makeStyles((theme) => ({
name: {
fontWeight: theme.typography.fontWeightBold,
},
}));
اگر به pnpm تغییر دهم، با خطای زیر مواجه میشوم:
Overload 1 of 2, '(style: Styles<Theme, {}, "name">, options?: Pick<WithStylesOptions<Theme>, "link" | "index" | "media" | "name" | "meta" | "flip" | "element" | "defaultTheme" | "generateId" | "classNamePrefix">): (props?: any) => ClassNameMap<...>', gave the following error.
Argument of type '(theme: Theme) => { name: { fontWeight: FontWeight; }; }' is not assignable to parameter of type 'Styles<Theme, {}, "name">'.
Type '(theme: Theme) => { name: { fontWeight: FontWeight; }; }' is not assignable to type 'StyleRulesCallback<Theme, {}, "name">'.
Call signature return types '{ name: { fontWeight: FontWeight; }; }' and 'StyleRules<{}, "name">' are incompatible.
The types of 'name' are incompatible between these types.
Type '{ fontWeight: Property.FontWeight; }' is not assignable to type 'CSSProperties | CreateCSSProperties<{}> | PropsFunc<{}, CreateCSSProperties<{}>>'.
Type '{ fontWeight: Property.FontWeight; }' is not assignable to type 'CreateCSSProperties<{}>'.
Types of property 'fontWeight' are incompatible.
Type 'FontWeight' is not assignable to type 'FontWeightProperty | PropsFunc<{}, FontWeightProperty>'.
Type 'string & {}' is not assignable to type 'FontWeightProperty | PropsFunc<{}, FontWeightProperty>'.
Type 'string & {}' is not assignable to type '"lighter"'.
Overload 2 of 2, '(styles: Styles<Theme, {}, "name">, options?: Pick<WithStylesOptions<Theme>, "link" | "index" | "media" | "name" | "meta" | "flip" | "element" | "defaultTheme" | "generateId" | "classNamePrefix">): (props: {}) => ClassNameMap<...>', gave the following error.
Argument of type '(theme: Theme) => { name: { fontWeight: FontWeight; }; }' is not assignable to parameter of type 'Styles<Theme, {}, "name">'.
Type '(theme: Theme) => { name: { fontWeight: FontWeight; }; }' is not assignable to type 'StyleRulesCallback<Theme, {}, "name">'.
3 export const useAlertConfigurationNameStyles = makeStyles((theme) => ({
~~~~~~~~~~~~~
4 name: {
~~~~~~~~~~~
...
6 },
~~~~~~
7 }));
~~
Found 1 error.
هر دو از همان نسخهی @material-ui/core استفاده میکنند که در package.json گنجانده شده است.
آیا کسی میداند علت ممکن است چه باشد، یا چگونه میتوانم بیشتر بررسی کنم؟ من با TypeScript زیاد آشنا نیستم، بنابراین نمیدانم از اینجا باید به کجا بروم.
پاسخ شماره ۱
ممکن است این مشکل را به دلیل گزینههای tsconfig.json تجربه کنید. مطمئن شوید که declaration و declarationMap را روی false تنظیم کردهاید
"compilerOptions": {
"declaration": false,
"declarationMap": false,
(...)
}
