November 2018
Beginner
502 pages
10h 22m
English
interface ICourseMark { courseName: string; grade: string;}
We can use this interface as follows:
const geography: ICourseMark = { courseName: "Geography", grade: "B"}
The grades can only be A, B, C, or D. How can we create a stronger typed version of the grade property in this interface?
We can use a union type:
interface ICourseMark { courseName: string; grade: "A" | "B" | "C" | "D";}
function isNumberPopulated(field: number): boolean { return field !== null && field !== undefined;}function isStringPopulated(field: string): boolean { return field ...Read now
Unlock full access