小编Mag*_*ull的帖子

Java:当foo()在超类中时,this.foo()和super.foo()是否相同?

说我有以下课程:

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(),对吧?

java extends this super

19
推荐指数
2
解决办法
1096
查看次数

在 React 应用程序中收到错误“检测到嵌套 CSS,但 CSS 嵌套尚未正确配置”?

我已经将我的 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 …

reactjs postcss tailwind-css

15
推荐指数
1
解决办法
2万
查看次数

在 React TypeScript 中推断 2 个 props 之间的泛型类型

我相信这是可能的,但我不太擅长 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)

也许这非常简单,但我发现确切地知道要搜索哪些术语来找到它有点棘手。

附加问题:推断的通用行可以扩展组件中的接口吗?也许所需要的只是&它......?

type-inference typescript reactjs

9
推荐指数
1
解决办法
6403
查看次数

如何解码/编码电缆调制解调器配置文件?

我目前正在研究DOCSIS及相关的一些内部工作原理。我有点困惑的一件事是如何制作电缆调制解调器配置文件。

根据我收集到的信息:

  • CM 配置是基于TLV格式的二进制文件。
  • 这些配置使用 TFTP 服务器进行部署,并在调制解调器启动时通过 DHCP 提示给调制解调器本身。

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.

  • Is TLV just a generic method of stringing data together? It seems like TLV is used in both binary forms and json-like strings of clear text.
  • Is the T and/or L parts of TLV a set size (in bytes)? How do …

binaryfiles tlv

5
推荐指数
1
解决办法
3889
查看次数

是否可以使用 React 和 TypeScript 将子组件限制为特定组件?

将 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)

typescript reactjs

5
推荐指数
1
解决办法
4224
查看次数