flow-runtime icon indicating copy to clipboard operation
flow-runtime copied to clipboard

flow-runtime ParameterType remember doesn't work with arrays

Open vlsergeyatsbt opened this issue 4 years ago • 1 comments

This is a:

  • [X] Bug Report
  • [ ] Feature Request
  • [ ] Question
  • [ ] Other

Which concerns:

  • [X] flow-runtime
  • [ ] babel-plugin-flow-runtime
  • [ ] flow-runtime-validators
  • [ ] flow-runtime-mobx
  • [ ] flow-config-parser
  • [ ] The documentation website

What is the current behaviour?

class TestClass<ValueType>  {

  do(  ) {
    const items : ValueType[] = JSON.parse( '[{ "a": null, "b": "b" }, { "a": "a", "b": null }]' );
    console.log(items);
  }

}

const testClass : TestClass = new TestClass();
testClass.do();
RuntimeTypeError: [1].a must be null
Expected: null
Actual Value: "a"
Actual Type: string
-------------------------------------------------
[1].b must be a string
Expected: string
Actual Value: null
Actual Type: null

What is the expected behaviour?

Shall not throw an exception.


Which package versions are you using?

    "@babel/cli": "^7.5.5",
    "@babel/core": "^7.5.5",
    "@babel/plugin-proposal-class-properties": "^7.5.5",
    "@babel/plugin-proposal-decorators": "^7.4.4",
    "@babel/preset-env": "^7.5.5",
    "@babel/preset-flow": "^7.0.0",
    "babel-plugin-flow-runtime": "^0.19.0",
    "flow-runtime": "^0.17.0"
{
  "plugins": [
    [ "flow-runtime", {
      "assert": true,
      "annotate": true
      } ],
    [ "@babel/plugin-proposal-decorators", { "decoratorsBeforeExport": true}],
    "@babel/plugin-proposal-class-properties",
  ],
  "presets": [
    "@babel/preset-flow",
    "@babel/preset-env",
  ]
}

vlsergeyatsbt avatar Aug 20 '19 09:08 vlsergeyatsbt

For anyone who have the same issue. Workaround is to remove type template and use "internal" type alias:

type ValueType = any;

class TestClass  {

  do(  ) {
    const items : ValueType[] = JSON.parse( '[{ "a": null, "b": "b" }, { "a": "a", "b": null }]' );
    console.log(items);
  }

}

const testClass : TestClass = new TestClass();
testClass.do();

vlsergey avatar Oct 18 '19 06:10 vlsergey