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

no-type-alias could be helpful #56

Closed
mightyiam opened this issue Mar 1, 2019 · 6 comments
Closed

no-type-alias could be helpful #56

mightyiam opened this issue Mar 1, 2019 · 6 comments

Comments

@mightyiam
Copy link
Owner

https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-type-alias.md

@swansontec
Copy link
Contributor

After reading the docs for that, as well as the other rules in this repo, I would configure no-type-alias like this:

{
  // Enables things that are difficult to achieve in other ways:
  allowAliases: 'in-unions-and-intersections',
  allowLiterals: 'in-unions-and-intersections',
  allowMappedTypes: 'in-unions-and-intersections',

  // The `prefer-function-type` rule forces this:
  allowCallbacks: 'always'
}

@mightyiam
Copy link
Owner Author

@swansontec, I read the rule doc and I agree with the options suggested by you.

@LinusU
Copy link
Contributor

LinusU commented Aug 13, 2019

I use case I've ran into lately is:

import firebase = require('firebase')

type DocumentReference = firebase.firestore.DocumentReference

// ...

function foo(ref: DocumentReference) {
  // ...
}

@swansontec
Copy link
Contributor

@LinusU That's a valid point! Shortening long names might also be a valid use-case.

The @typescript-eslint/prefer-function-type and @typescript-eslint/prefer-interface rules already get rid of the most "wrong" uses of the type keyword, so the remaining cases would be things like intersections, unions, or your example shortening long names. In that case, maybe no-type-alias doesn't give much additional benefit?

The main benefit I can see would be banning "useless" type aliases like type Username = string. It's too bad there is no @typescript-eslint/no-useless-type rule, or at least an option to the allowAliases configuration that would trivial cases like this.

@mightyiam
Copy link
Owner Author

Shortening a nested type does seem like a constructive pattern. Isn't there another way to get a reference to that nested type other than with a type alias? And... did you check that this is an error according to this rule? It seems like it would be, always. I'm closing this on the count of @LinusU's shortening example. If anyone has an idea, please reopen.

@LinusU
Copy link
Contributor

LinusU commented Aug 14, 2019

Shortening a nested type does seem like a constructive pattern. Isn't there another way to get a reference to that nested type other than with a type alias?

I would love to know this as well! ☺️

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