When using an import such as below:
import { Component, OnInit } from "@angular/core";
Is it convention to use single or double quotes around "@angular/core"?
TSLint complians saying:
[tslint] " should be ' (quotemark)
This seems odd as the file was created with the angular-cli command
ng g c someComponent
so it would seem that it would create the imports to typescripts standards so now I'm not sure which format is correct.
In US English, you must use double quotation marks. Single quotation marks are used for quotes within quotes. In UK English, it's most common to use single quotation marks, with double quotation marks for quotes within quotes, although the other way around is acceptable too.
Generally, double quotes are used for string representation and single quotes are used for regular expressions, dict keys or SQL. Hence both single quote and double quotes depict string in python but it's sometimes our need to use one type over the other.
The main difference between double quotes and single quotes is that by using double quotes, you can include variables directly within the string. It interprets the Escape sequences. Each variable will be replaced by its value.
Generally, there is no difference between using double or single quotes, as both of them represent a string in the end. There is only one difference in the usage of single and double quotes, and it comes down to what quote character you need to escape using the backslash character (\): \' or \”.
The Google Style Guide has long said:
Prefer ' over "
And this has made its way into many tools, such as TSLint.
When everyone used to put lots of HTML inside strings in languages like JavaScript and PHP this used to be a big deal, as it meant you could use double-quoted HTML attributes inside a string without escaping the quotes.
This use case is less important these days, because we don't tend to concatenate HTML strings.
TSLint rules are over and above the TypeScript compiler and you can disable them or configure them to your liking. The team is more important than the tool - so bend it to the will of the team.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With