Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import Statements Single vs Double Quotes

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.

like image 251
Tony Scialo Avatar asked Nov 25 '17 21:11

Tony Scialo


People also ask

When should I use single or double quotation marks?

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.

Is it better to use single quotes or double quotes in Python?

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.

What is the difference between single and double quoted string?

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.

Is there a difference between single and double quotes in JavaScript?

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 \”.


1 Answers

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.

like image 145
Fenton Avatar answered Dec 03 '22 21:12

Fenton