menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

T vs any i...
source image

Dev

1M

read

399

img
dot

Image Credit: Dev

T vs any in TypeScript

  • Both 'any' and generic 'T' in TypeScript mean 'could be any kind of type', but there is a significant difference.
  • 'any' is never constrained, while generic 'T' is always under constraint somewhere.
  • Example with generic 'T': 'T' is under constraint, specifying that 'stuff' can only be of 'T' type, and the return type can only be an array of 'T'.
  • Example with 'any': 'any' is not constrained by anything, allowing code to be valid even if it doesn't achieve the initial goal.

Read Full Article

like

24 Likes

For uninterrupted reading, download the app