2016-12-22 1 views
2

나는 Record이 새로운 수업을 만든다는 것을 알고 있습니다. : 그러면 왜 흐름에 다음과 같은 유형 체킹 :레코드 클래스 및 인스턴스를 입력하는 방법은 무엇입니까?

대비 일반 클래스를 사용하는 경우 (예상대로), 다음이 유형 체킹하지 않습니다에서
const Person = Record({fname  : null, lname: null}); 
const Person2 = Record({fnameMANGLED: null, lname: null});   
const p : Person2 = new Person({fname: 'joe', lname: 'doe'}); // shouldn't Flow complain? 

:

class A{constructor() {}}; 
class B{constructor() {}};   
const a: A = new A(); 

답변

1

v4.0.0-rc.5부터 RecordOf<T>RecordFactory<T> 유형이 추가되었습니다.

다음은 이러한 흐름 유형을 사용하는 방법에 대한 docs의 스 니펫입니다.

import type { RecordFactory, RecordOf } from 'immutable'; 

// Use RecordFactory<TProps> for defining new Record factory functions. 
type Point3DProps = { x: number, y: number, z: number }; 
const makePoint3D: RecordFactory<Point3DProps> = Record({ x: 0, y: 0, z: 0 }); 
export makePoint3D; 

// Use RecordOf<T> for defining new instances of that Record. 
export type Point3D = RecordOf<Point3DProps>; 
const some3DPoint: Point3D = makePoint3D({ x: 10, y: 20, z: 30 }); 
관련 문제