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

tslint: add rule "no-angle-bracket-type-assertion" #12

Open
carlo-nomes opened this issue Jan 10, 2019 · 2 comments
Open

tslint: add rule "no-angle-bracket-type-assertion" #12

carlo-nomes opened this issue Jan 10, 2019 · 2 comments
Labels
enhancement New feature or request tslint

Comments

@carlo-nomes
Copy link

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[X] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/NationalBankBelgium/stark/blob/master/CONTRIBUTING.md#got-a-question-or-problem

Current behavior

For now there is no specific ts-lint rule for type assertion.
This means both of these are valid:

  • const circle: Circle = shape as Circle
  • const circle: Circle = <Circle> shape;

Expected behavior

To increase consistency the rule "no-angle-bracket-type-assertion" should be enabled in /packages/stark-build/config/tslint.json to enforce the first way of type assertion.
Or the other option can be chosen, but there no is rule available yet. (palantir/tslint#1228)

It is a choice between the two ways, but using as has a slight preference. (Because of compatibility with JSX).
TypeScript documentation
TSLint documentation

Minimal reproduction of the problem with instructions

const circle: Circle = shape as Circle; // Passes
const circle: Circle = <Circle> shape; // Passes

What is the motivation / use case for changing the behavior?

Increasing consistency in the source code.

Environment


Angular CLI: 7.1.4
Node: 11.4.0
OS: darwin x64
Angular: 7.1.1

For Tooling issues:
- Node version: v11.4.0  
- Platform:  All

Others:
- TSLint: 5.11.0
- TypeScript: Version 3.2.2

@carlo-nomes
Copy link
Author

There does exist an extension that supports type assertion. ajaff/tslint-consistent-codestyle

@christophercr christophercr changed the title Add "Rule: no-angle-bracket-type-assertion" to tslint linting: add rule "no-angle-bracket-type-assertion" to TSLint config Jan 10, 2019
@christophercr christophercr changed the title linting: add rule "no-angle-bracket-type-assertion" to TSLint config build: add rule "no-angle-bracket-type-assertion" to TSLint config Jan 10, 2019
@christophercr
Copy link
Collaborator

There is also another tslint extension from Microsoft: https://github.com/Microsoft/tslint-microsoft-contrib

In there, the rule is: prefer-type-cast

@SuperITMan SuperITMan transferred this issue from NationalBankBelgium/stark Jun 6, 2019
@SuperITMan SuperITMan added enhancement New feature or request tslint labels Jun 6, 2019
@SuperITMan SuperITMan changed the title build: add rule "no-angle-bracket-type-assertion" to TSLint config tslint: add rule "no-angle-bracket-type-assertion" to TSLint config Jun 6, 2019
@SuperITMan SuperITMan changed the title tslint: add rule "no-angle-bracket-type-assertion" to TSLint config tslint: add rule "no-angle-bracket-type-assertion" Jun 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request tslint
Projects
None yet
Development

No branches or pull requests

3 participants