Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Book Chapter: Static Typing with TypeScript #118

Merged
merged 9 commits into from Apr 22, 2019

Conversation

luyangkenneth
Copy link
Member

@luyangkenneth luyangkenneth commented Apr 11, 2019

Fixes #117

Here's the permalink to the preview page: https://deploy-preview-118--learningresources.netlify.com/contents/javascript/staticTypingInJavascript.html


Structure:

  • What is Static Typing?
  • Adding Static Typing to JavaScript
  • TypeScript Basics
  • Getting Started with TypeScript (Additional Resources)

@luyangkenneth luyangkenneth force-pushed the static-typing-with-typescript branch 2 times, most recently from 2a4222c to 0767763 Compare April 16, 2019 09:27
@luyangkenneth
Copy link
Member Author

@marvinchin Can you help me to review the Intro section? 😄

Copy link
Contributor

@marvinchin marvinchin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the introduction does a good job in highlighting what static typing is, and why developers might want to consider typescript. Looking forward to the rest of the article!

contents/javascript/staticTypingWithTypescript.md Outdated Show resolved Hide resolved
contents/javascript/staticTypingWithTypescript.md Outdated Show resolved Hide resolved
contents/javascript/staticTypingWithTypescript.md Outdated Show resolved Hide resolved
contents/javascript/staticTypingWithTypescript.md Outdated Show resolved Hide resolved
contents/javascript/staticTypingWithTypescript.md Outdated Show resolved Hide resolved
contents/javascript/staticTypingWithTypescript.md Outdated Show resolved Hide resolved
@luyangkenneth luyangkenneth force-pushed the static-typing-with-typescript branch 2 times, most recently from 4dc507b to 4ce0782 Compare April 18, 2019 17:24
@luyangkenneth
Copy link
Member Author

@marvinchin Added some new sections :D

Copy link
Contributor

@marvinchin marvinchin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good additions to show the reader how using typescript looks like, and highlights the key functionalities of typescript 🙂 Just have a couple of questions regarding the organisation and phrasing of the article.

contents/javascript/staticTypingWithTypescript.md Outdated Show resolved Hide resolved
contents/javascript/staticTypingWithTypescript.md Outdated Show resolved Hide resolved

If we try to assign it a `number` value later on, the TypeScript compiler will raise an error:
```typescript
myString = 123; // error: 123 is not assignable to type 'string'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to include a screenshot of the compiler/IDE displaying the error, to make it a little more "realistic" to the reader?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha I definitely considered this. There a few reasons why I decided against it eventually.

  1. Readers won't be able to copy-paste the code snippets if they wanna play with the examples themselves - I'm going to introduce https://www.typescriptlang.org/play/ in the last section.

  2. If I hover over the error, it will block the rest of the code. Of course, I can work around this by adding more line breaks above the errored line, but it'll be uglier. I also want to simplify the error messages, so using comments would be better than letting readers see the actual IDE errors. This is especially true in the case of objects.

Screenshot 2019-04-20 at 1 50 31 PM

  1. Screenshots are much harder to update later on if someone else wants make any changes / additions to the article. Also, a new screenshot might have different syntax highlighting, different font, etc. which makes the article look less consistent overall.

contents/javascript/staticTypingWithTypescript.md Outdated Show resolved Hide resolved

Sometimes, we don't know what the type of a variable might be. In those cases, we would use the `any` type to opt out of compile-time type checking. For example, `myList` is an array that contains elements with a mix of different types:
```typescript
function printItemsToConsole(list: any[]): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would the method name logItems be shorter? 😛

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because these examples are focusing on the types - but we still need some kind of implementation to help contextualize the example - I wanted to have implementation that was as simple as possible, to not distract the reader from the main focus. So I think I want to stick to a method name that is glaringly explicit (as opposed to abstract, which I might favor in a real-world codebase).


## TypeScript Basics

### Compilation to JavaScript
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some thoughts - I wonder how important this is for a reader who wants to know what typescript is. while it is important, I feel it may fall outside the "core" functionality of typescript, which is type checking, and hence it may make more sense to place it after the section on type checking.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intended this to be a slightly more detailed introduction to what TypeScript's relationship with JavaScript actually is, which I think is important to understand from the beginning - I can imagine lacking clarity about this as a new reader. Putting it here is also to extend on the statically typed superset of JavaScript that compiles to plain JavaScript one-liner in the previous section.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's kinda like providing that little bit of theoretical knowledge before diving into "how do we actually use this" for the rest of the article.

contents/javascript/staticTypingWithTypescript.md Outdated Show resolved Hide resolved
@luyangkenneth
Copy link
Member Author

@marvinchin Just made some updates - if these are ok, I just have my last section remaining! (It's on the way)

Copy link
Contributor

@marvinchin marvinchin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me so far!

@luyangkenneth
Copy link
Member Author

Ready for final review!

Copy link
Contributor

@damithc damithc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly good 👍 Added a few comments.

contents/javascript/staticTypingWithTypescript.md Outdated Show resolved Hide resolved
contents/javascript/staticTypingWithTypescript.md Outdated Show resolved Hide resolved
contents/javascript/staticTypingWithTypescript.md Outdated Show resolved Hide resolved

{{ booktitle | safe }}

# Static Typing with TypeScript
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ATM it is not clear who the target audience is.
How about we make this Static Typing in JavaScript and add a couple of lines about Flow? That way, the target audience is clearly JS programmers who are looking to add static typing to their code. Also, it will be similar to the article on JavaScript modules.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about adding more lines about Flow - almost all of the basics in Flow and TypeScript are similar so there's a lot of overlap there, unlike in the JavaScript modules article.

I'm happy to change the title to Static Typing in JavaScript - what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you think the suggested heading fits the current content without adding more on Flow, go ahead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok! Done 🙂

@damithc damithc merged commit e079df1 into se-edu:master Apr 22, 2019
@damithc
Copy link
Contributor

damithc commented Apr 22, 2019

Merged and deployed.
Good work @luyangkenneth
Thanks to the reviewer too.

@luyangkenneth luyangkenneth deleted the static-typing-with-typescript branch April 22, 2019 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Static Typing with TypeScript
3 participants