谁能解释一下下面这段代码中发生了什么?为什么会这样呢?我预计变量a也会改变......
var base = {
cars: {
color: "blue",
brand: "Ford"
}
}
var a = base.cars;
base.cars = function () { console.log("example method") }
console.log(base) // changed to method
console.log(a) // still is object - why?
Run Code Online (Sandbox Code Playgroud) 为什么在输入不应返回任何内容的函数然后访问返回某些值的props.onClick内部Message组件后不会出现错误?
type MessageProps = {
onClick: () => void,
value?: string
}
const Message: React.FunctionComponent<MessageProps> = (props: any) => {
return (
<>
<h1>Example message</h1>
<button onClick={props.onClick}>click</button>
</>
)
}
const App = (props: any) => {
return (
<div className="App">
<Message onClick={() => 2} />
</div>
);
}
export default App;
Run Code Online (Sandbox Code Playgroud) 我尝试将自定义颜色应用于按钮组件,但出现错误。可能的解决方案是什么?
我像文档中那样进行了模块模块增强,但问题仍然存在:
https://mui.com/material-ui/customization/palette/#adding-new-colors
信息:
Button.d.ts(34, 5): The expected type comes from property 'color' which is declared here on type 'IntrinsicAttributes & { component: ElementType<any>; } & { children?: ReactNode; classes?: Partial<ButtonClasses> | undefined; ... 10 more ...; variant?: "text" | ... 2 more ... | undefined; } & Omit<...> & CommonProps & Omit<...>'
const theme = createTheme({
palette: {
primary: {
main: '#ff0000',
},
play: {
main: '#ffffff',
contrastText: 'black'
},
moreInfo: {
main: '#6c6c6e',
contrastText: 'white'
},
tonalOffset: 0.2, …Run Code Online (Sandbox Code Playgroud)