I'm encountering an issue in my React Typescript app where I am seeing the following error message:
webpack compiled with 1 warning
ERROR in src/App.tsx:30:21
TS2304: Cannot find name 'DecompressionStream'.
28 | const enc = new TextEncoder()
29 | const dc = new TextDecoder()
> 30 | const gunzip = new DecompressionStream('gzip')
| ^^^^^^^^^^^^^^^^^^^
Interestingly, when I run a Node script without TypeScript, everything runs smoothly. The CompressionStream and DecompressionStream objects are present in that scenario. However, it appears that TypeScript, during its checks (or maybe due to the fact that it's being built as a web application?), believes that we are missing an import or require statement.
I've tried various import approaches without success as shown below:
import { DecompressionStream } from 'compression-streams'
const DecompressionStream = require('DecompressionStream')
const DecompressionStream = globalThis.DecompressionStream
All the resources I've consulted regarding the CompressionStreams API do not specify any module name, leading me to suspect that I might be overlooking something. I've also searched for a Typescript @types/
module related to this, but it seems that such a module does not exist. Could it be that this web API is too recent for TypeScript support?