For npm: you can run:
npm update -g typescript
By default, it will install latest version.
For yarn, you can run:
yarn upgrade typescript
Or you can remove the orginal version, run yarn global remove typescript
, and then execute yarn global add typescript
, by default it will also install the latest version of typescript.
more details, you can read yarn docs.