Issue
In a project that my team is working on, we have type aliases for primitive types. The reason, I got from my team, for this is to have consistency across the codebase.
type FruitName = string;
const fruits: FruitName[] = ['apple', 'banana']
Now, because of this, if I use alias in a function argument, and when I hover on it, my IDE shows that the type is FruitName. It gives a feeling that maybe FruitName is an object instead of a string.
Is there an ESLint plugin that can help to avoid type aliases for primitive types?
Solution
You can use @typescript-eslint/no-type-alias rule like this:
'@typescript-eslint/no-type-alias': ['error', {
allowAliases: 'in-unions-and-intersections',
allowConstructors: 'never',
allowLiterals: 'always',
allowGenerics: 'always',
allowTupleTypes: 'always',
allowMappedTypes: 'always'
}]
Answered By - Sabrina B.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.