说我有以下课程:
class Foo {
protected void method() {}
}
class Bar extends Foo {
}
Run Code Online (Sandbox Code Playgroud)
此时,从类Bar,我可以通过method()两种方式访问:
super.method();this.method();从我看来,他们似乎执行相同的行动.在这种情况下,这两者之间是否存在差异?是否有首选版本可供使用?
使用super是有道理的,因为它method()是超类的一部分.this我认为使用也很有道理,因为Bar将继承Foo类的属性,因此method(),对吧?
我已经将我的 CRA 项目升级到 TailwindCSS 3,但现在 CSS 嵌套不再起作用。启动服务器后,控制台会输出:
(8:3) Nested CSS was detected, but CSS nesting has not been configured correctly.
Please enable a CSS nesting plugin *before* Tailwind in your configuration.
See how here: https://tailwindcss.com/docs/using-with-preprocessors#nesting
Run Code Online (Sandbox Code Playgroud)
但是,我不知道必须采取什么措施来纠正这个问题。我尝试使用 Tailwind 设置一个普通的 CRA 项目(遵循本指南)只是为了确保没有冲突,但仍然没有成功。
postcss.config.js:
(8:3) Nested CSS was detected, but CSS nesting has not been configured correctly.
Please enable a CSS nesting plugin *before* Tailwind in your configuration.
See how here: https://tailwindcss.com/docs/using-with-preprocessors#nesting
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我在Tailwind之前添加了嵌套插件。在我看来,好像插件没有被检测到。我也尝试用postcss-nesting相同的结果替换它。
require('tailwind/nesting')注意:我还尝试按照指南建议使用数组语法。
有趣的是,从 postcss.config.js 中删除所有插件(或使用require …
我相信这是可能的,但我不太擅长 TS 中的高级输入(还),所以:
我想让 React 组件在一个 prop 中接受任何对象形状的数组,然后在不同的(事件函数)prop 中发出相同类型。
interface Props {
data: AnyGenericRow[];
onRow: (row: AnyGenericRow) => void;
}
Run Code Online (Sandbox Code Playgroud)
我应该如何打字AnyGenericRow才能达到我想要的效果?我想我需要以某种方式推断类型data,然后将该推断的类型应用于签名onRow。
用法示例:
const rows: Array<{ foo: 'bar' }> = [];
/* ... */
<Component data={rows} onRow={row => {
/* can `row` be detected as a type of { foo: 'bar' } ? */ }
} />
Run Code Online (Sandbox Code Playgroud)
也许这非常简单,但我发现确切地知道要搜索哪些术语来找到它有点棘手。
附加问题:推断的通用行可以扩展组件中的接口吗?也许所需要的只是&它......?
我目前正在研究DOCSIS及相关的一些内部工作原理。我有点困惑的一件事是如何制作电缆调制解调器配置文件。
根据我收集到的信息:
I'm interested in knowing how these config files are structured. I have next to no knowledge of TLV aside from what I've read these past days.
将 React 与 TypeScript 结合使用,有多种方法可以定义 的类型children,例如将其设置为JSX.ElementorReact.ReactChild或extending PropsWithChildren。但是这样做,是否可以进一步限制React子元素可以是哪个特定元素?
function ListItem() {
return (
<li>A list item<li>
);
}
//--------------------
interface ListProps {
children: React.ReactChild | React.ReactChild[]
}
function List(props: ListProps) {
return (
<ul>
{props.children} // what if I only want to allow elements of type ListItem here?
</ul>
);
}
Run Code Online (Sandbox Code Playgroud)
鉴于上述情况,可以List设置为仅允许类型为 ? 的子级吗ListItem?类似于以下(无效)代码:
interface ListProps {
children: React.ReactChild<ListItem> | React.ReactChild<ListItem>[]
}
Run Code Online (Sandbox Code Playgroud) reactjs ×3
typescript ×2
binaryfiles ×1
extends ×1
java ×1
postcss ×1
super ×1
tailwind-css ×1
this ×1
tlv ×1