2 ms·
The difference comes when you interface with other well-typed code and want to convert from any/unknown down to a specific type. For example: function handl
by badlucklottery 4y ago
The difference comes when you interface with other well-typed code and want to convert from any/unknown down to a specific type.
For example:
function handleString(s: string) {
//...
}
declare const a: any;
declare const u: unknown;
handleString(a); // works with zero intervention
handleString(u); // error: Argument of type 'unknown' is not assignable to parameter of type 'string'
handleString(u as string); // works again with explicit re-typing