Let's have a go at some questions on advanced types:
- We have an interface that represents a course result, as follows:
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 have the following functions that validate that numbers and strings are populated with a value:
function isNumberPopulated(field: number): boolean {
return field !== null && field !== undefined;
}
function isStringPopulated(field: string): boolean {
return field !== null && field !== undefined && field !== "";
}
How can we combine these into a single function called isPopulated with signature overloads...