I'm using VSCode/Typescript React 3.4.3 for a React Native project and I'm having troubles at runtime with TextEncoder
The ts code:
...var encoder = new TextEncoder();var b: Uint8Array = encoder.encode(newName);...
My tsconfig libs:
"module": "es2015","target": "es2015","jsx": "react","lib": ["es5", "es2017", "dom"]
This compile fines but it fails at runtime when it tries to create the instance of TextEncoder:
"ReferenceError: Can't find variable: TextEncoder"
I do not understand what is wrong here.
Any help appreciated
EDIT 1: Well the fact is that when you debug your JS code, it runs in Chrome which leads to success. But when you're not, you finish to discover that the JavaScriptCore neither support TextEncorder nor btoa.
So I have chosen to favor the use of npm modules (text-encoding and base-64):
import * as encoding from 'text-encoding';import {encode as btoa} from 'base-64'...var encoder = new encoding.TextEncoder();...