0
是否有可能获得更严格的编译时检查使用接口的参数构造函数?默认行为似乎太宽松。如何在流类型接口上对类的构造函数参数进行严格类型检查?
例如,给定下面的类:
// @flow
'use strict';
import type { Bar } from './bar';
export default class Foo {
_bar: Bar;
_name: string;
constructor (bar: Bar, name: string) {
this._bar = bar;
this._name = name;
}
}
在另一处定义了以下接口:
// @flow
'use strict';
export interface Bar {
doSomething(someArg: string);
}
如果我创建的Foo无效的情况下以某种原始类型我的我会得到一个错误:
// In any of these flowtype checking works and fails because
// it knows those things are not Bar.
new Foo('bar', 'someName');
new Foo(1, 'someName');
new Foo({}, 'someName');
但是,如果我做这样的事情愚蠢:
new Foo(new Function(), 'someName');
流动型是完全满意这个和那种失败甚至具有定义的接口的在第一位置的目的。如果我可以传入任何类型的实例对象,并且flowtype没有看到传入的内容与接口不匹配,它应该抛出一个错误,就像它为{}
所做的那样。
是否有一些配置需要更改或我做错了什么?
编辑:
我觉得这可能是一个错误,并已提交了issue。