フローは、カスタムクラス定義でインデックス可能なプロパティを許可していないようです。理由はわかりませんが。
AFAIKには2つの回避策があります。
Object
明示的にクラスを拡張します。
/* @flow */
const methods: Array<string> = ['bar', 'baz'];
class Foo extends Object {}
// ^^^^^^^^^^^^^^
methods.forEach((method: string) => {
Foo.prototype[method] = function () {
console.log('method', method);
}
});
または、インターフェイスでインデックス可能な署名を宣言します。
/* @flow */
interface Ix {
[key: any]: any
}
class StrFunIx implements Ix {
$key: string;
$value: function;
}
class Foo extends StrFunIx {}
const methods: Array<string> = ['bar', 'baz'];
methods.forEach((method: string) => {
Foo.prototype[method] = x => x;
});
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加