mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Global var definitions for TextDecoder and TextEncoder collide with the globals defined by "lib.dom.d.ts". Ideally we would be able to conditionally define TextDecoder and TextEncoder if they are not already defined in the current context. Since we cannot do conditional definitions in an ambient context, we export these types so the user can do this themselves (see tests). - Move global type definitions to namespace to prevent collisions with "lib.dom.d.ts" TextDecoder and TextEncoder. - Update name of namespace from "fastTextEncoder" to "fastTextEncoding" to match package name. - Update tests to manually define global vars TextDecoder and TextEncoder.
23 lines
784 B
TypeScript
23 lines
784 B
TypeScript
// Declare globals in non-DOM environment
|
|
declare let TextDecoder: fastTextEncoding.TextDecoder;
|
|
declare let TextEncoder: fastTextEncoding.TextEncoder;
|
|
|
|
const encoder1 = new TextEncoder();
|
|
const _encoder2 = new TextEncoder('utf-8');
|
|
|
|
const _encoderEncoding = encoder1.encoding;
|
|
|
|
const _encoded1 = encoder1.encode('foo');
|
|
const _encoded2 = encoder1.encode('foo', { stream: false });
|
|
|
|
const decoder1 = new TextDecoder();
|
|
const _decoder2 = new TextDecoder('utf-8');
|
|
const _decoder3 = new TextDecoder('utf-8', { fatal: false });
|
|
|
|
const _decoderEncoding = decoder1.encoding;
|
|
const _decoderFatal = decoder1.fatal;
|
|
const _decoderIgnoreBOM = decoder1.ignoreBOM;
|
|
|
|
const _decoded1 = decoder1.decode(new Uint8Array(16));
|
|
const _decoded2 = decoder1.decode(new Uint8Array(16), { stream: false });
|