Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the standard for use of quotes in Typescript?

I notice in my application that TsLint is suggesting:

static $inject = [
        '$http',
        '$q',
        '$scope',
        'configService',
        'stateService',
        'utilityService'
    ];

for the above that:

Message 2   TsLint: ' should be "

Is this a suggested standard now for Typescript ?

like image 845
Samantha J T Star Avatar asked Aug 22 '14 19:08

Samantha J T Star


People also ask

What are quotation marks used for in JavaScript?

Strings in JavaScript are contained within a pair of either single quotation marks '' or double quotation marks "". Both quotes represent Strings but be sure to choose one and STICK WITH IT.

Should I use single or double quotes in react?

Single Quotes are More Common A few repositories of popular JavaScript projects reveals that single quotes are favored over double quotes. You can see that front-end libraries (React, Angualar) have more double quotes than the other libraries as might have to do with the presence of HTML fragments.

When assigning text to strings you can use single or double quotes?

use double quotes for strings and single quotes for chars. I prefer to use the same quoting across the board and so stick with double quotes for JS.

Do single or double quotes matter in JavaScript?

There is really no difference in the end between using single or double quotes, meaning they both represent a string in the end. The system doesn't really care which one you use (but you might?). No need to escape the other character within a string.


3 Answers

This was the first result in my google search for: "double vs single quotes typescript."

Considering the accepted answer is a little old (but still valid from the docs) I would like to add this quote from: https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines updated on November 27, 2015:

Use double quotes for strings.

Granted "the code is more what you'd call 'guidelines' than actual rules." :)

like image 67
crowebird Avatar answered Oct 17 '22 03:10

crowebird


I would go with single quotes. I pretty much agree with this guy:

  • Prefer single quotes (') unless escaping.

Reason: More JavaScript teams do this (e.g.airbnb, standard, npm, node, google/angular, facebook/react). Its easier to type (no shift needed on most keyboards). 

Prettier team recommends -single quotes as well double quotes

Also, even dotnet new templates use single quotes for Angular apps.

like image 41
Saša Ćetković Avatar answered Oct 17 '22 03:10

Saša Ćetković


There is no particular standard to use single quotes for characters and double quotes for string but it is suggested to use double quotes for strings and vice versa.

From the docs:

Just like JavaScript, TypeScript also uses the double quote (") or single quote (') to surround string data.

like image 25
Rahul Tripathi Avatar answered Oct 17 '22 03:10

Rahul Tripathi