Giter Club home page Giter Club logo

Comments (5)

mhegazy avatar mhegazy commented on May 18, 2024

A PR would be appreciated. Also we should add a linter rule for it.

from typescript-handbook.

DanielRosenwasser avatar DanielRosenwasser commented on May 18, 2024

Tagging @wanderer06 because he asked on Gitter.

It was used in the same example because the point was that you can use either type of string literal. If you see other locations, we'll take a PR, but I'm going to close this unless you've found others.

from typescript-handbook.

wanderer06 avatar wanderer06 commented on May 18, 2024

I'd say it depends on the level of consistency you'd like to achieve. Generally the quoting style is consistent within an example, but not across multiple chunks of code.

One example I can think of is the Writing declaration files page, where it uses single quotes in one example:

// Super-chainable library for eagles
import Eagle = require('./eagle');

// Call directly
Eagle('bald').fly();

// Invoke with new
var eddie = new Eagle('Mille');

// Set properties
eddie.kind = 'golden';

But switches to double just down below:

import sayHello = require("say-hello");
sayHello("Travis");

Then there are cases where using a string literal in code description seems at random:

/**
 * Takes a string and adds "padding" to the left.
 * If 'padding' is a string, then 'padding' is appended to the left side.
 * If 'padding' is a number, then that number of spaces is added to the left side.
 */

Sometimes a return value, type or variable will be quoted in some comments, but not in others:

Variable Declaration.md
function f() {
    var a = 10;
    return function g() {
        var b = a + 1;
        return b;
    }
}

var g = f();
g(); // returns 11;

Down below:

function f(shouldInitialize: boolean) {
    if (shouldInitialize) {
        var x = 10;
    }

    return x;
}

f(true);  // returns '10'
f(false); // returns 'undefined'

Or

function foo() {
    // okay to capture 'a'
    return a;
}

// illegal call 'foo' before 'a' is declared
// runtimes should throw an error here
foo();

let a;
let animal = new Animal("Goat");
let rhino = new Rhino();
let employee = new Employee("Bob");

animal = rhino;
animal = employee; // Error: Animal and Employee are not compatible

There are cases where this will be quoted as md quote inside a code block, making it use neither quoting style:

//...
    createCardPicker: function() {
        // Notice: the line below is now a lambda, allowing us to capture `this` earlier
        return () => {
//...

Interfaces.md includes some reversed quotes:

In the above example, ‘SelectableControl’ contains all of the members of ‘Control’, including the private ‘state’ property. Since ‘state’ is a private member it is only possible for descendants of ‘Control’ to implement ‘SelectableControl’. This is because only descendants of ‘Control’ will have a ‘state’ private member that originates in the same declaration, which is a requirement for private members to be compatible.

Should the docs use single or double quotes consistently throughout all examples?
Does this apply to the text outside the code blocks as well?
ie this is called 'Declaration Merging' vs this is called "Declaration Merging".

What about getting started file examples?

var browserify = require("browserify");
var tsify = require("tsify");

browserify()
    .add('main.ts')
    .plugin('tsify', { noImplicitAny: true })
    .bundle()
    .pipe(process.stdout);

from typescript-handbook.

DanielRosenwasser avatar DanielRosenwasser commented on May 18, 2024

In code samples

  • We use single quotes in comments to refer to entities.
  • All strings should be double-quoted unless as part of the example.

Outside of code samples

  • References to code should use backticks (```).
  • New terms should be in italics, though I could see double-quotes being acceptable in some contexts.

from typescript-handbook.

DanielRosenwasser avatar DanielRosenwasser commented on May 18, 2024
/**
 * Takes a string and adds "padding" to the left.
 * If 'padding' is a string, then 'padding' is appended to the left side.
 * If 'padding' is a number, then that number of spaces is added to the left side.
 */

This was to basically indicate that "padding" is a kind of wishy-washy term, and other uses of "padding" refer to the parameter name.

from typescript-handbook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.