scrimba
Understanding Typescript In Depth
Typescript Section 2 - Interface & classes #19
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Typescript Section 2 - Interface & classes #19
AboutCommentsNotes
Typescript Section 2 - Interface & classes #19
Expand for more info
index.ts
run
preview
console
interface InterfaceA {
m1: string;
}
interface InterfaceB {
m2: string;
}
type TypeAB = InterfaceA & InterfaceB;

interface X1 {
m1: string;
}
interface X2 {
m1?: string;
}
type Same = X1 & X2;
let same: Same = { m1: "This is required" };

// extending interfaces
interface InterfaceA {
m1: string;
}

interface InterfaceB {
m2: string;
}

// difference between type & interafces
type TPrimitive1 = string;
type TPrimitive2 = { m1: string };
// type can't be used to implement
class ExtendPrimitiv1 implements TPrimitive1 {
// Does not compile
}
//

interface InterfaceMergeAB extends InterfaceA, InterfaceB {
m3: string;
}
Console
"Hello from JavaScript"
,
index.html
-3:58