3 ms·
Are there any plans to catch something like this: function f(x: any): T { return x }
by k__ 10y ago
Are there any plans to catch something like this:
function f(x: any): T {
return x
}
- pimterry 10y agoThat would defeat the point of 'any', right? It's for variables that you want to allow to do anything (including be a T) without the compiler complaining. If you don't want that behaviour, don't given x 'any' type. In that case there I'd probably use '{}' instead, and then use type guards (https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-guards-and-differentiating-types https://www.typescriptlang.org/docs/handbook/advanced-types.... to convince TypeScript that it's a T (whatever that means).