首页 / typescript / Limit Use of the any Type
let ageInYears: number;
ageInYears = '12';
// ~~~~~~~ Type 'string' is not assignable to type 'number'.
ageInYears = '12' as any; // OK
ageInYears += 1; // OK; at runtime, ageInYears is now "121"
function calculateAge(birthDate: Date): number {
// ...
}
let birthDate: any = '1990-01-19';
calculateAge(birthDate); // OK