1let stringOrNullValue: string | null = null;
2//it an take null as well as other type.
3
4stringOrNullValue = "someString";
1interface Employee1 {
2 name: string;
3 salary: number;
4}
5
6var a: Employee1 = { name: 'Bob', salary: 40000 }; // OK
7var b: Employee1 = { name: 'Bob' }; // Not OK, you must have 'salary'
8var c: Employee1 = { name: 'Bob', salary: undefined }; // OK
9var d: Employee1 = { name: null, salary: undefined }; // OK
10
11// OK
12class SomeEmployeeA implements Employee1 {
13 public name = 'Bob';
14 public salary = 40000;
15}
16
17// Not OK: Must have 'salary'
18class SomeEmployeeB implements Employee1 {
19 public name: string;
20}
21