Answers for "typescript type or null"

0

typescript type or null

let stringOrNullValue: string | null = null;
//it an take null as well as other type.

stringOrNullValue = "someString";
Posted by: Guest on August-07-2021
0

typescript declaring null

interface Employee1 {
    name: string;
    salary: number;
}

var a: Employee1 = { name: 'Bob', salary: 40000 }; // OK
var b: Employee1 = { name: 'Bob' }; // Not OK, you must have 'salary'
var c: Employee1 = { name: 'Bob', salary: undefined }; // OK
var d: Employee1 = { name: null, salary: undefined }; // OK

// OK
class SomeEmployeeA implements Employee1 {
    public name = 'Bob';
    public salary = 40000;
}

// Not OK: Must have 'salary'
class SomeEmployeeB implements Employee1 {
    public name: string;
}
Posted by: Guest on July-06-2021

Code answers related to "typescript type or null"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language