Learning More TypeScript Fundamentals

SetUp App to Follow Along

There is a repo provided, but I wanted to set up a new project and get more experience with doing so.

index.ts

SetUp a Configuration File

In the main root folder, create a new file: tsconfig.json .

tsconfig.json

Tuple

— an array of a fixed length and convention (types determined)

Objects

— Instead of key: value, you have key: type, by default all fields are mandatory

Logical And (&&) and Or (||) Operators

Intersection Types— And(&)

now x has all the properties as both A and Z
Great example from Codingblast⁴

Type Systems & Type Equivalence

Wider vs Narrower

A level of specificity. The widest type is any. Types get narrower from there. Any ‘any’ → Array ‘any[]’ → Array of Strings ‘string[]’ → Array of 3 → ‘[string, string, string]’ — > Nothing ‘never’

Function Types

*Note: Command click will take you from a function to an interface/definition of type. 2 ways a function can be written:

Rest Params

New to me is the concept of rest params.

the type of an array in TS has to be array-like, bc it will be ‘consumed’ as array

Overload Signatures

With function overloading, you can have multiple functions with the same name but different parameter types and return type. However, the number of parameters should be the same.⁶

The last function should have the function implementation.

Lexical Scope

The value of ‘this’ when you invoke a function. In TypeScript, this becomes part of a function signature.

Interfaces & Type Aliases

Type Aliases → giving any type a name, any type that you create with a variable, you can create an alias for:

CLASSES

Access Modifier Keywords: (who can access this)
- public → everyone
- protected → me and subclasses
- private → only me

Definite Assignment Operator

The definite assignment assertion is a feature that allows a ! to be placed after instance property and variable declarations to relay to TypeScript that a variable is indeed assigned for all intents and purposes, even if TypeScript’s analyses cannot detect so.⁷

  1. TypeTypeScript 3 Fundamentals, v2 | Frontend Masters | “https://frontendmasters.com/courses/typescript-v2/
  2. Literal Types | TypeScript | “https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types
  3. Intersection Types | CodingBlast | “https://codingblast.com/typescript-intersection-types/
  4. Union Types | CodingBlast | “https://codingblast.com/typescript-union-types-type-guards-type-aliases/
  5. JavaScript | Rest Parameter | Geeks For Geeks | “https://www.geeksforgeeks.org/javascript-rest-operator/
  6. TypeScript — Function Overloading | Tutorials Teacher | “https://www.tutorialsteacher.com/typescript/function-overloading
  7. Definite Assignment Assertions | TypeScript | “https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Osha Groetz

Osha Groetz

93 Followers

Software Engineer. A new addict of ReactJS & Javascript, CSS & APIs, with a little dabbling in Ruby, Ruby On Rails…