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

getParentOfType inside flow gives Typescript error #1542

Closed
3 tasks done
ErnoW opened this issue Jun 29, 2020 · 2 comments
Closed
3 tasks done

getParentOfType inside flow gives Typescript error #1542

ErnoW opened this issue Jun 29, 2020 · 2 comments

Comments

@ErnoW
Copy link

ErnoW commented Jun 29, 2020

Bug report

  • I've checked documentation and searched for existing issues
  • I've made sure my project is based on the latest MST version
  • Fork this code sandbox or another minimal reproduction.

Sandbox link or minimal reproduction code
Link to reproduction: https://codesandbox.io/s/zealous-field-hq5ck

const Child = types.model({}).actions(self => ({
  fetchName: flow(function* fetchName() {
    // As soon as url is used in a yield,
    // it will throws an error: "... because it does not have a type annotation and is referenced directly or indirectly in its own initializer"
    const url = getParentOfType(self, Parent);
    yield fetch(url);
  })
}));
const Parent = types.model({
  url: types.maybe(types.string),
  child: types.optional(types.late(() => Child), {})
});

tsconfig needs to have:

"compilerOptions": {
  "strict": true,
}

Describe the expected behavior
When I get the data from getParentOfType, and use it inside a yield of a flow, I would like to not getting a typescript error.

Describe the observed behavior
The Parent and Child both get an error:

implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

This only happens when I use data from getParentOfType inside the yield of a flow, and strict mode is enabled in tsconfig. The functionality behaves correctly though.


Related issue: #1305 (closed but not solved)
Same issue referenced in a comment: #1157 (comment)

@antondomratchev
Copy link

@ErnoW Based on your example its hard to know what your expected behavior should be. The current code example doesn't really show the error nor does the referenced code annotate any TS types. Can you update the example to show the described error?

@ErnoW ErnoW closed this as completed Dec 22, 2020
@miguelhrocha
Copy link

@ErnoW did you find a solution for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants