首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >当使用"className“时,反应本地类型记录给我一个TS错误

当使用"className“时,反应本地类型记录给我一个TS错误
EN

Stack Overflow用户
提问于 2022-07-08 10:21:16
回答 3查看 1.4K关注 0票数 2

使用了一段时间的反应,但新的反应本地人。

我使用的是顺风和https://tailwindcss-react-native.vercel.app/installation

代码语言:javascript
运行
复制
import { View, Text } from "react-native";
import React from "react";

export default function Navigation() {
  return (
    <View className="grid h-screen w-screen place-items-center">
      <Text className="text-red-800">Test</Text>
    </View>
  );
}

“顺风作案”,文本是红色的,但是我在^^的类名下得到了TS错误。

代码语言:javascript
运行
复制
No overload matches this call.
  Overload 1 of 2, '(props: ViewProps | Readonly<ViewProps>): View', gave the following error.
    Type '{ children: Element; className: string; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<View> & Readonly<ViewProps> & Readonly<{ children?: ReactNode; }>'.
      Property 'className' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<View> & Readonly<ViewProps> & Readonly<{ children?: ReactNode; }>'.
  Overload 2 of 2, '(props: ViewProps, context: any): View', gave the following error.
    Type '{ children: Element; className: string; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<View> & Readonly<ViewProps> & Readonly<{ children?: ReactNode; }>'.
Property 'className' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Text> & Readonly<TextProps> & Readonly<{ children?: ReactNode; }>'.ts(2769)

我已经跟踪了世博类型记录的设置,我的tsconfig看起来如下:

代码语言:javascript
运行
复制
{
  "compilerOptions": {},
  "extends": "expo/tsconfig.base"
}
EN

回答 3

Stack Overflow用户

发布于 2022-07-22 08:44:40

默认情况下,尾风响应本机快速启动设置不包括对TypeScript的支持。然而,文档提到了如何添加它:

创建一个文件(如。src/tailwindcss react native.d.ts)并粘贴这一行

代码语言:javascript
运行
复制
import "tailwindcss-react-native/types.d";

包含此文件后,TypeScript错误将消失。

票数 2
EN

Stack Overflow用户

发布于 2022-10-19 13:03:25

我也遇到过同样的问题,包含这些类型的最简单的修复方法是创建一个新的app.d.ts文件,并添加一个引用以下类型的三元斜杠指令:

代码语言:javascript
运行
复制
/// <reference types="nativewind/types" />

如果这不能解决您的问题,为了消除红线,您可以在文件的顶部添加@ts-nocheck。(免责声明,此解决方案不能解决问题,只需通过禁用TS检查特定文件来获取警告区域)

票数 1
EN

Stack Overflow用户

发布于 2022-07-08 11:17:22

React本机ViewText组件不接受className支持,只接受style

查看参考资料:https://reactnative.dev/docs/text

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72909992

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档