小编Abu*_*fia的帖子

在 Typescript 中使用 React Props 展开运算符(错误:...可以使用约束 {} 的不同子类型进行实例化)

我正在尝试使用 Typescript 在 React 中编写一个高阶组件,该组件接收道具,“消耗”其中一个,然后将其余部分传递给子组件。

function testConnect<T>(Child: React.ComponentType<T>): React.ComponentType<T> {

  type InitialState = {
    iS: StoreShape.State;
  };

  type LAP = InitialState & T;

  const Connector = (props: LAP) => {
    const { iS, ...rest } = props;
    // do something with iS
    return (
      <Child // Visual Studio complains about this line.
        {...rest}
      />
    );
  };

  return Connector;
}
Run Code Online (Sandbox Code Playgroud)

但是,这失败并出现错误: 'Pick<LAP, Exclude<keyof T, "iS">>' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different …

javascript typescript reactjs

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

相当于golang中的cat &lt;&lt;EOF

我正在尝试执行与此等效的操作:

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
  name: testMap
  namespace: default
data:
  details:
    host: "localhost:${reg_port}"
EOF
Run Code Online (Sandbox Code Playgroud)

在戈兰。

我目前的尝试归结为:

func generateConfig(port string) string {
    return `
apiVersion: v1
kind: ConfigMap
metadata:
  name: testMap
  namespace: default
data:
  details:
    host: "localhost:" + port`
}

func main() {
  exec.Command("kubectl", "apply", "-f", "-", generateConfig(5000))
}
Run Code Online (Sandbox Code Playgroud)

我并不特别惊讶地发现它不起作用,并出现错误:

error: Unexpected args: [
apiVersion: v1
kind: ConfigMap
metadata:
    name: testMap
    namespace: default
data:
    details:
        host: "localhost:5000"]
Run Code Online (Sandbox Code Playgroud)

我认识到我将这些作为参数传递,并且 kubectl 需要一个文件,但是我发现自己完全不知道如何继续。

我宁愿不创建临时文件或调用单独的 bash 脚本,因为这看起来比我希望的更混乱。

shell go kubectl

-1
推荐指数
1
解决办法
1791
查看次数

标签 统计

go ×1

javascript ×1

kubectl ×1

reactjs ×1

shell ×1

typescript ×1