为什么我收到此 TypeScript 错误消息以及如何修复它?
找不到模块“@env”或其相应的类型声明
当我使用这个时会发生这种情况:
import { FB_ID } from '@env';
Run Code Online (Sandbox Code Playgroud)
Tt 不应命名为 @env,它应命名为“react-native-dotenv”,但在我的配置中我将其命名为 @env,以便我可以使用它,并且可以检索 FB_ID 值。它有效,但我收到 TypeScript 错误。
这是我设置 moduleName 的地方:
import { FB_ID } from '@env';
Run Code Online (Sandbox Code Playgroud)
那么我该如何解决它呢?
ts配置:
['module:react-native-dotenv', {
"envName": "APP_ENV",
"moduleName": "@env",
"path": ".env",
"blocklist": null,
"allowlist": null,
"safe": false,
"allowUndefined": true,
"verbose": false
}]
Run Code Online (Sandbox Code Playgroud) 我想翻译我的颜色,但不知道该怎么做。
const Item = memo(({ color, index, lastIndex, translateName, style, activeColor, onPress }: IColorItem) => {
return (
<Text>{translateName}</Text>
)
// @ts-ignore
}, isEq);
const Colors = ({ colors, style, activeColor, onPress }: IColors) => {
const { t } = useTranslation();
const renderItem: ListRenderItem<ColorsType> = ({ item, index }) => (
<Item
color={item}
translateName={t('colors.color', { color: item })}
index={index}
style={style}
activeColor={activeColor}
lastIndex={colors.length - 1}
onPress={onPress}
/>
)
return (
<View style={s.container}>
<FlatList
data={colors as ColorsType[]}
renderItem={renderItem}
style={s.flatList}
keyExtractor={(item, i) …
Run Code Online (Sandbox Code Playgroud) 我有带有星号图标的产品,可以将此产品添加到愿望清单中。我映射了 10 个产品列表,每个映射有 3 个产品,例如:
(我将其映射到 Pagerview 以滑动到下一个产品)
产品组件
const ListProducts = [
{
id: 1,
products: [{
product_id: 1,
photos: [...]
}]
},
{
id: 2,
products: [{
product_id: 1,
photos: [...]
}]
}
{
id: 3,
products: [{
product_id: 1,
photos: [...]
}]
},
{
id: 4,
products: [{
product_id: 1,
photos: [...]
}]
}
...
];
function isEq(prev, next) {
if(prev.is_wishlist === next.is_wishlist) {
return true;
}
}
const Item = memo(({ id, photos, is_wishlist, onPress, onPressWishlist …
Run Code Online (Sandbox Code Playgroud) 我使用 i18next,我想将 t 函数 prop 传递到我的界面。
经验:
const { t } = useTranslation();
export interface ITranslate {
translate: ... type?
}
Run Code Online (Sandbox Code Playgroud)
“t”变量的类型是什么?
向下滑动时如何关闭底部工作表?
我使用这个库:
https://gorhom.github.io/react-native-bottom-sheet
Run Code Online (Sandbox Code Playgroud) 我有这个模型:
export interface SizeAndColors {
size: string;
color: string;
}[];
Run Code Online (Sandbox Code Playgroud)
然后我有另一个模型,我需要 sizeAndColor 但没有数组。
export interface Cart {
options: SizeAndColors
}
Run Code Online (Sandbox Code Playgroud)
我怎么能在选项中说我想要这个没有数组的接口呢?那可能吗 ?