Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flow-runtime ParameterType remember doesn't work with arrays #237

Open
2 of 10 tasks
vlsergeyatsbt opened this issue Aug 20, 2019 · 1 comment
Open
2 of 10 tasks

flow-runtime ParameterType remember doesn't work with arrays #237

vlsergeyatsbt opened this issue Aug 20, 2019 · 1 comment
Labels

Comments

@vlsergeyatsbt
Copy link

vlsergeyatsbt commented Aug 20, 2019

This is a:

  • Bug Report
  • Feature Request
  • Question
  • Other

Which concerns:

  • 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",
  ]
}
@vlsergey
Copy link
Contributor

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 added a commit to vlsergey/flow-runtime that referenced this issue Jun 22, 2020
vlsergey added a commit to vlsergey/flow-runtime that referenced this issue Jun 22, 2020
vlsergey added a commit to vlsergey/flow-runtime that referenced this issue Jun 29, 2020
vlsergey added a commit to vlsergey/flow-runtime that referenced this issue Jun 30, 2020
gajus added a commit that referenced this issue Jul 6, 2020
Fix for #237: record actual Type for ParameterType if implicit type is available
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants