我正在尝试使用 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 …
我正在尝试执行与此等效的操作:
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 脚本,因为这看起来比我希望的更混乱。