Typescript Flashcards
What is typescript and why I can’t learn it without knowing javascript?
Typescript is a superset of javascript to improve the development experience, therefore typescript is created on top of javascript.
What typescript compiles (aka transpile) to? Is it compiled to machine code? Is it readable?
to javascript. no. Yes, readable javascript
What are the three main benefits of typescript?
typing, organization (classes, namespaces, modules) and tooling.
If typescript is transpiled to js, will debug of js code (which actually runs on browser) be mapped to our typescript code?
yes.
What is the name of the typescript compiler? Will tsc command look for ts files in the current dir and subfolders?
tsc. yes
How to install typescript?
npm install -g Typescript
Can I configure tsc to build a specific target version of js?
yes.
Where are typescript configurations stored? How to generate one?
tsconfig.json. tsc –init
What is type inference in typescript?
typescript infers the type of vars when not specified;
does typescript support access modifiers in classes? What are the three of them? What is the default when not explicitly defined?
public, protected and private. public.
does the tsconfig.json file support configuration inheritance (meaning root configs can be overwritten by lower level folders)? What does the option extends do in the tsconfig file?
yes. define the “base” tsconfig file.
what is the option “watch”: true means in the tsconfig file?
changes to tsconfig files are automatically compiled to js
What happens when the compiler doesn’t find a tsconfig.json file in the current dir?
It will go up in the folder hierarchy looking for one
What does the strict: true option in the tsconfig.json file does?
enable all strict options to true (the most strict option of all).
does webpack support compiling typescript?
yes. via ts-loader
does the bundle.js generated by webpack available locally?
no. just served to the browser (via webpack developer server)
what is the number type represents in typescript and javascript?
float point values
What’s the one primitive type exclusively available in typescript?
enum
Does typescript support hoisting? What does it mean?
Yes. Means the is run once to load all variables and then executed again to actually run the code.
If type is inferred on typescript why would I annotate the types in my code?
to give code clarity.
does let support hoisting? which one does?
no. only var.
What is the Never built-in type?
Is a type that means the function is an infinite loop or always throw an exception.
When the type Any is useful?
Useful when integrating third party js libs.
What is union type? how to declare one?
means a variable can have two or more types. Declared as let asd: number | string
What is type assertion? how is it called in Delphi/C#?
means you can cast to a type. typecast
What are the two ways to do a type assertion on typescript?
myVar
myVar as number
do I need to restart npm/webpack server when the tsconfig.json file is changed?
yes.
how to check the type of a variable?
typeof myvar === ‘string’
how to declare an optional parameter in a function? Where this param needs to be?
function fun(a: string, b?:string). Needs to be at the end.