我使用 vite 创建了新的 React Typescript 应用程序
我执行npm create vite@latest然后选择typescript-swc
我不明白为什么我不能使用新的装饰器
function loggedMethod(originalMethod: any, context: ClassMethodDecoratorContext) {
console.log(context)
const methodName = String(context.name)
function replacementMethod(this: any, ...args: any[]) {
console.log(`LOG: Entering method '${methodName}'.`)
const result = originalMethod.call(this, ...args)
console.log(`LOG: Exiting method '${methodName}'.`)
return result
}
return replacementMethod
}
class Person {
name: string
constructor(name: string) {
this.name = name
}
@loggedMethod
greet() {
console.log(`Hello, my name is ${this.name}.`)
}
} …Run Code Online (Sandbox Code Playgroud) 当使用多个样式组件时,最上面的一个会覆盖其他默认的 props。
import { styled } from '@mui/material/styles'
import { Badge } from '@mui/material'
const Badge1 = styled(Badge)``
// this works if Badge1 is used directly: <Badge1 />
Badge1.defaultProps = {
max: Infinity
}
const Badge2 = styled(Badge1)`` // styled Badge1
// this overrides defaultProps from Badge1. Prop max: Infinity does no apply here
Badge2.defaultProps = {
variant: 'standard'
}
Run Code Online (Sandbox Code Playgroud)
Badge2 只有变体:“标准”默认道具。它跳过最大值:无穷大
如何保留每个级别的所有默认道具