응용 프로그램 코드의 Flow 객체 유형 정의에서 키를 가져올 수 있습니까? 즉, 어떤 식 으로든 런타임 코드에서 구체화 된 흐름 유형 정의입니까?코드에서 Flow 객체 유형의 키 가져 오기
사용 사례 :
type Props = {
userID: string,
size: number | PhotoSize,
subscribePresence: Function,
unsubscribePresence: Function,
presenceStatus: ?PresenceStatus,
photoURL: ?string,
userName: ?string,
};
class Photo extends Component<Props> {
// ...
render() {
const { userID, size, presenceStatus } = this.props;
// Other props used elsewhere in the component
const restProps = _.omit(this.props, ???)
}
}
render
에서 사용되지 않는 다른 소품이 있으므로 확산 destructure (const { /* etc */ ... rest} = this.props
)가 작동하지 않을 것입니다. 그러나 지정된 다른 소품 (className
, id
등)을 찾아야합니다.
???
은 Object.keys(Props)
과 유사한 것으로부터 유래 될 수 있습니까? 내가 알 수있는 한 타입 정의가 컴파일되므로 런타임 코드에서 Props
을 참조하면 RuntimeError: Props is not defined
이 발생합니다.
아니요, 모든 유형 정보는 컴파일시 –