100% found this document useful (1 vote)
68 views

Type Script

This document discusses TypeScript type annotations and type checking. It introduces common TypeScript types like string, number, boolean, arrays, tuples, unions, intersections, generics, and type aliases. It also covers type declarations, interfaces, modules, ambient declarations, and how TypeScript compiles without runtime impact while still providing type safety.

Uploaded by

kasim
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
68 views

Type Script

This document discusses TypeScript type annotations and type checking. It introduces common TypeScript types like string, number, boolean, arrays, tuples, unions, intersections, generics, and type aliases. It also covers type declarations, interfaces, modules, ambient declarations, and how TypeScript compiles without runtime impact while still providing type safety.

Uploaded by

kasim
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

strict object literal checking

Module
Freshness
Global

type StrOrNum = string|number; Type Alias

T&U Intersection Type


DefinitelyTyped
string | number Union Type
which files
Compilation Context
Generics compiler options

Type Declaration Space


:TypeAnnotation Declaration Spaces
Variable Declaration Space

var myPoint: { x: number; y: number; }; :{ / Structure/ } Inline Type Annotation


Modules

compose multiple type annotations into a single file for common types, interfaces,
global.d.ts
zero runtime JS impact Interfaces global namespace

implements browser
Project
ambient declarations common JS stuff JS envs
string node.js
type annotation TypeScript
number Primitive Types --noLib

boolean
lib.d.ts ?

[] to any valid type annotation Arrays


automatically included in the compilation context

any Compiler target effect

--strictNullChecks null --lib


Special Types
--strictNullChecks undefined tsconfig.json no runtime

Ambient Declarations overloading just documention


void
functions not arrow function
: [string, number] Tuple Type

organize a collection of related values Enums Callable Newable ?

is a declaration file .d.ts extension

JavaScript is valid TypeScript

narrow down the type within a conditional block


Type Guard
typeof

instanceof
no any runtime is not casting
inferred type
in Type Assertion
as foo vs. <foo>

a compile time construct

Double assertion
the assertion from type S to T succeeds ?
either S is a subtype of T

or T is a subtype of S

You might also like