Can't find variable: Buffer

I ran npm install buffer and put this at the top of files that needed Buffer:

global.Buffer = global.Buffer || require('buffer').Buffer

In TypeScript I had to import Buffer explicitly.

import { Buffer } from "buffer"

I would have expected that the compiler would complain about Buffer being missing before the import and/or that "source.organizeImports": true would have removed the line when saving the file, but neither were true.

@ehacinom's solution also worked.