-
Notifications
You must be signed in to change notification settings - Fork 27
Small Grammar and Wording Changes #5
base: master
Are you sure you want to change the base?
Changes from all commits
c337bf4
9b00b5e
7014685
a9173e7
482810a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -185,7 +185,7 @@ npm install -g typescript | |
| > This installs the TypeScript Compiler `tsc` globally. | ||
| > You can use `npx` or similar tools if you'd prefer to run `tsc` from a local `node_modules` package instead. | ||
|
|
||
| Now let's move to an empty folder and try writing our first TypeScript program: `hello.ts`: | ||
| Now create an empty directory named ts-example and create a new file called: `hello.ts` and input the following code: | ||
|
|
||
| ```ts | ||
| // Greets the world. | ||
|
|
@@ -208,7 +208,7 @@ Well, there were no type errors, so we didn't get any output in our console sinc | |
| But check again - we got some *file* output instead. | ||
| If we look in our current directory, we'll see a `hello.js` file next to `hello.ts`. | ||
| That's the output from our `hello.ts` file after `tsc` *compiles* or *transforms* it into a JavaScript file. | ||
| And if we check the contents, we'll see what TypeScript spits out after it processes a `.ts` file: | ||
| And if we check the contents of the .js file, we'll see what TypeScript spits out after it processes a `.ts` file: | ||
|
|
||
| ```js | ||
| // Greets the world. | ||
|
|
@@ -217,7 +217,10 @@ console.log("Hello world!"); | |
|
|
||
| In this case, there was very little for TypeScript to transform, so it looks identical to what we wrote. | ||
| The compiler tries to emit clean readable code that looks like something a person would write. | ||
| While that's not always so easy, TypeScript indents consistently, is mindful of when our code spans across different lines of code, and tries to keep comments around. | ||
| While that's not always so easy, TypeScript: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the general idea that all lists of things need to be bullets? I'd like to understand the motivation.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, so I proposed bullets because it seemed hard to read as one long sentence. It visually helped when I separated them as a bulleted list. Could just be a me thing! |
||
| * Indents consistently | ||
| * Is mindful of when our code spans across different lines of code | ||
| * And tries to keep comments around | ||
|
|
||
| What about if we *did* introduce a type-checking error? | ||
| Let's rewrite `hello.ts`: | ||
|
|
@@ -246,7 +249,7 @@ Thanks TypeScript! | |
|
|
||
| One thing you might not have noticed from the last example was that our `hello.js` file changed again. | ||
| If we open that file up then we'll see that the contents still basically look the same as our input file. | ||
| That might be a bit surprising given the fact that `tsc` reported an error about our code, but this based on one of TypeScript's core values: much of the time, *you* will know better than TypeScript. | ||
| That might be a bit surprising given the fact that `tsc` reported an error about our code, but this is based on one of TypeScript's core values: much of the time, *you* will know better than TypeScript. | ||
|
|
||
| To reiterate from earlier, type-checking code limits the sorts of programs you can run, and so there's a tradeoff on what sorts of things a type-checker finds acceptable. | ||
| Most of the time that's okay, but there are scenarios where those checks get in the way. | ||
|
|
@@ -321,7 +324,7 @@ That's a feature, and it's best not to add annotations when the type system woul | |
|
|
||
| ## Erased Types | ||
|
|
||
| Let's take a look at what happens when we compile with `tsc`: | ||
| Let's take a look at the differences in the JavaScript code created from `tsc`: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like that this calls out that we're looking at the JS code, but "differences" is kind of left hanging in terms of what the other thing we're comparing against is.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm I see your point. Maybe "Lets take a look at the JavaScript code created when we compile with tsc"? |
||
|
|
||
| ```js | ||
| function greet(person, date) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -187,7 +187,7 @@ TypeScript doesn't hurt us here at all, but this is behavior worth noting if you | |
| TypeScript can often help you catch bugs early on, but if you choose to do *nothing* with a value, there's only so much that it can do without being overly prescriptive. | ||
| If you want, you can make sure you handle situations like these with a linter. | ||
|
|
||
| One last word on narrowing by truthiness is that Boolean negations with `!` filter out from negated branches. | ||
| One last word on narrowing by truthiness is that Boolean negations with `!`, filter out from negated branches. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sentence is a complete disaster (I can barely figure out what it means) and should just be rewritten. The proposed change doesn't improve it. See "Using A Comma Before A Verb In Relative Clause"
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's an honor to receive this feedback 😅
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Totally agree the change was not the best as I too had issues figuring out what it meant. I didn't want to change too much but a whole new sentence is preferred. |
||
|
|
||
| ```ts | ||
| function multiplyAll(values: number[] | undefined, factor: number): number[] | undefined { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand how specifying the directory name improves the clarity. Anyway for all code or filenames we've been using
fixedwidthformattingThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking in more of a beginner sense and doing many workshops I've noticed that many people need things specifically spelled out for them. Versus when we write docs we know what we mean.