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

Return type conventions #1203

Closed
zepumph opened this issue Feb 28, 2022 · 2 comments
Closed

Return type conventions #1203

zepumph opened this issue Feb 28, 2022 · 2 comments
Assignees

Comments

@zepumph
Copy link
Member

zepumph commented Feb 28, 2022

In the doc it says:

Consider using explicit annotations for object literals and function return types even when they can be inferred.

@zepumph zepumph self-assigned this Feb 28, 2022
@zepumph
Copy link
Member Author

zepumph commented Feb 28, 2022

This was discussed during today's dev meeting about typescript conventions. Here are our decisions:

  • We all felt like having explicit return types makes sense in all classes to ensure an API doesn't change. This is beneficial for common code and sims, in part because it helps replace the jsdoc.
  • That said, you don't have to duplicate this for getter/setter methods AND their es5 getters and setters. For example, if there is a getX() method with an explicit return type, you don't need to provide the return type for the get x() getter too. It is up to the dev. That said, if we use this lint rule, we have to include them anyways: https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/explicit-function-return-type.md
  • It is important to be explicit when defining the API, but using that API, it is best to infer, that reduces technical debt for refactors. This also applies for callback for generally.
    • For example using a scenery event listener, it is best to not duplicate those types in case IInputListener changes its API.
    • Also for internal, simple callbacks, it could be more harm than its worth to add types.

We want to start with https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/explicit-function-return-type.md.

@zepumph
Copy link
Member Author

zepumph commented Jul 14, 2022

We currently spun up our own lint rule to just enforce on methods, not setters or getters. See

const exemptMethods = [ 'get', 'set', 'constructor' ];
. This has been working well for us. In the future, if we want to add getters and setters to the rule, we will. I don't think there is anything else for this issue.

@zepumph zepumph closed this as completed Jul 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants