Classes

Classes

Classes work similarly to object literal types and interfaces with one exception: they have both a static and an instance type. When comparing two objects of a class type, only members of the instance are compared. Static members and constructors do not affect compatibility.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Animal {
  feet: number;
  constructor(name: string, numFeet: number) { }
}
 
class Size {
  feet: number;
  constructor(numFeet: number) { }
}
 
let a: Animal;
let s: Size;
 
a = s;  //OK
s = a;  //OK
doc_TypeScript
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.