Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 流中具有混合值的对象属性赋值_Javascript_Flowtype - Fatal编程技术网

Javascript 流中具有混合值的对象属性赋值

Javascript 流中具有混合值的对象属性赋值,javascript,flowtype,Javascript,Flowtype,遇到流问题,无法找到解决方法 最好用代码来描述: type Mytype = { propA?: string, propB?: number, }; type myTypeProps = $Keys<typeof MyType>; const source : Mytype = { propA: 'hello', propB: 10, }; const myFunc = (pro

遇到流问题,无法找到解决方法

最好用代码来描述:

   type Mytype = {
      propA?: string,
      propB?: number,
    };

    type myTypeProps = $Keys<typeof MyType>;

    const source : Mytype = {
       propA: 'hello',
       propB: 10,
    };

    const myFunc = (props: Array<myTypeProps>, ): Mytype => {
       const dest:Mytype = {};
       props.forEach(propType => {
         dest[propType] = source[propType]; 
          //Flow Error because of 
          //type mismatch: string cannot be assigned to number
       });
       return dest;
    }
因此,明确说明键的作用是有效的,但当键被参数化时,就不起作用了

有什么想法吗

       const dest:Mytype = {};
       dest['propA'] = source['propA'];
       dest['propB'] = source['propB'];
       return dest;