Import Statements Single vs Double Quotes

Viewed 10068

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.

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.

Related