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

chore: Enforce array type styles in TypeScript #5765

Merged
merged 1 commit into from Apr 28, 2020

Conversation

jackfranklin
Copy link
Collaborator

This change enforces how we type arrays, e.g. choosing between:

  • string[]
  • Array<string>

I've gone for the array-simple option 1 which enforces that:

  • primitive types and type references use X[]
  • complex types use Array<X>

For example, we'd type an array of strings as string[], but an array
of a union type as Array<SomeUnionType>.

This change enforces how we type arrays, e.g. choosing between:

* `string[]`
* `Array<string>`

I've gone for the `array-simple` option [1] which enforces that:

* primitive types and type references use `X[]`
* complex types use `Array<X>`

For example, we'd type an array of strings as `string[]`, but an array
of a union type as `Array<SomeUnionType>`.

[1]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/array-type.md
Copy link
Member

@mathiasbynens mathiasbynens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I quite like the Array<> notation (even for primitive types and type references), but don't feel strongly.

@jackfranklin
Copy link
Collaborator Author

I don't feel strongly either - the one I picked follows the Google TS style guide, but happy to change it if you feel strongly. It's easily changed in the future too (it's fixable by eslint)

@jackfranklin jackfranklin merged commit d69fbb9 into master Apr 28, 2020
@jackfranklin jackfranklin deleted the standardise-array-types branch April 28, 2020 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants