You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is kinda working as intended. You could use the type parameter within the function body to ensure type safety or infer the return type:
functiona<T>(param: T){returnparam;// type parameter used in inferred return type}functionb<Textendsstring>(param: Map<string,T>){constv=param.get('foo')!;param.set('bar',v);// okparam.set('bar','v');// should be an error, replacing the type parameter with its constraint makes this pass type checking}
If you have a good idea how to handle such cases, especially the second case, I'm happy to change the rule.
Good point. It would probably be easy to check that the generic is not used as the return type, but it could be difficult to detect if the generic is used in the function body in some other way, such as in your Map example. 🤔
I would expect an error here. Or is the lint rule not designed to catch this?
The text was updated successfully, but these errors were encountered: