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

Error: "Don't use Function as a type." #28

Closed
liammulh opened this issue Oct 15, 2021 · 4 comments
Closed

Error: "Don't use Function as a type." #28

liammulh opened this issue Oct 15, 2021 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@liammulh
Copy link
Member

When I enter npm run serve, I occasionally see the following error.

 ERROR  Failed to compile with 1 errors                                                                                                                           7:13:10 PM

 error  in ./src/sequences/sequences.ts

Module Error (from ./node_modules/eslint-loader/index.js):

/Users/liam/numberscope-repos/liam-frontscope/src/sequences/sequences.ts
  2:36  error  Don't use `Function` as a type. The `Function` type accepts any function-like value.
It provides no type safety when calling the function, which can be a common source of bugs.
It also accepts things like class declarations, which will throw at runtime as they will not be called with `new`.
If you are expecting the function to accept certain arguments, you should explicitly define the function shape  @typescript-eslint/ban-types

✖ 1 problem (1 error, 0 warnings)


 @ ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/views/ToolMain.vue?vue&type=script&lang=js& 45:0-46 103:23-32 104:23-32
 @ ./src/views/ToolMain.vue?vue&type=script&lang=js&
 @ ./src/views/ToolMain.vue
 @ ./src/router.ts
 @ ./src/main.ts
 @ multi (webpack)-dev-server/client?http://10.201.65.95:8080/sockjs-node (webpack)/hot/dev-server.js ./src/main.ts

I don't think I was seeing this before ESLint was updated. I can't consistently reproduce this error. What am I missing here?

@liammulh liammulh added the bug Something isn't working label Oct 15, 2021
@liammulh
Copy link
Member Author

This is blocking my work on #25.

@liammulh liammulh self-assigned this Oct 15, 2021
gwhitney added a commit to gwhitney/frontscope that referenced this issue Oct 15, 2021
  This is done by creating and exporting a SequenceFormula class.

  In addition, adding this class seemed to spark an additional cascade
  of the Vue components needing to be (more) strongly typed. So the commit
  has numerous new type annotations (that should have no effect other than
  to aid TypeScript type checking) and a slight modification/simplification
  to the interface between sequences.ts and visualizers.ts on the one hand
  and ToolMain.vue on the other, since I could not figure out out to type
  the old interface (and a lot of extraneous information that was never
  being used was being passed anyway). Hopefully these changes will
  eliminate issue numberscope#28.

  Also, again as part of shoring up the typing, finally eliminates the
  spurious additional copy of the p5 code in src/assets, instead relying
  on npm install to get the proper copy of p5 in the right place. (The point
  being that the idiosyncratic copy was not typed, but npm brings in the
  type definitions automatically if you rely on it.)

  Resolves numberscope#14.
gwhitney added a commit to gwhitney/frontscope that referenced this issue Oct 15, 2021
  This is done by creating and exporting a SequenceFormula class.

  In addition, adding this class seemed to spark an additional cascade
  of the Vue components needing to be (more) strongly typed. So the commit
  has numerous new type annotations (that should have no effect other than
  to aid TypeScript type checking) and a slight modification/simplification
  to the interface between sequences.ts and visualizers.ts on the one hand
  and ToolMain.vue on the other, since I could not figure out out to type
  the old interface (and a lot of extraneous information that was never
  being used was being passed anyway). Hopefully these changes will
  eliminate issue numberscope#28.

  Also, again as part of shoring up the typing, finally eliminates the
  spurious additional copy of the p5 code in src/assets, instead relying
  on npm install to get the proper copy of p5 in the right place. (The point
  being that the idiosyncratic copy was not typed, but npm brings in the
  type definitions automatically if you rely on it.)

  Resolves numberscope#14.
@gwhitney
Copy link
Collaborator

If/when #31 is merged, please try rebasing on main and see if the issue resolves. If not, feel free to assign to me at that point, with a minimal example on top of main that displays the problem, as I've now gotten a fair amount of experience under my belt of adding typing to the Vue portions of frontscope (which is the only place that sequences.ts is used).

@gwhitney
Copy link
Collaborator

@liam-mulhall please advise if this issue remains; if not, please close.

@liammulh
Copy link
Member Author

liammulh commented Nov 5, 2021

I've yet to see this one again, so I'll close.

@liammulh liammulh closed this as completed Nov 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants