다른 인터페이스를 기반으로 새로운 증강 된 일반 인터페이스를 만들려고합니다. 기본 인터페이스는 객체가 가질 속성 ( root
) 을 정의합니다 . 증강 유형은 동일한 속성을 가져야하지만 any
값 대신 더 복잡한 객체를 얻습니다. 인터페이스 IStyleObj
는 제네릭 유형이 제네릭 인터페이스로 전달되는 제네릭 클래스 내부에서 사용됩니다.
내 실험에서 이러한 오류가 발생하고 수정 방법을 모릅니다.
"IStyleObj<T>"
'T' is declared but its value is never read.ts(6133)
"Key in keyof"
A computed property name must be of type 'string', 'number', 'symbol', or 'any'.ts(2464)
Member '[K in keyof' implicitly has an 'any' type.ts(7008)
"... T"
Cannot find name 'T'.ts(2304)
"class: any"
'any' only refers to a type, but is being used as a value here.ts(2693)
이것은 내 현재 코드입니다.
// Child.ts
interface IStyles {
root?: any
}
// Base.ts
interface IStyleObj<T> {
[K in keyof T]: {
class: any
style: any
}
}
export default class Base<IStyles = {}> {
get styles (): IStyleObj<IStyles> {
// ...
}
}
인터페이스는 매핑 된 유형이 될 수 없으며 유형 별칭 만 가능합니다. 이것은 작동합니다 :
// Child.ts
interface IStyles {
root?: any
}
// Base.ts
type IStyleObj<T> = {
[K in keyof T]: {
class: any
style: any
}
}
export default class Base<IStyles = {}> {
get styles (): IStyleObj<IStyles> {
return null!
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다