Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.
This repository was archived by the owner on Aug 2, 2022. It is now read-only.

Unable to use EOSJS in a Typescript Project #530

@thekevinbrown

Description

@thekevinbrown

Version of EOSJS
v20.0.0

Describe the bug
I'm trying to build a Typescript module which users can use to help test their smart contracts. This declares EOSJS as a peer dependency (and dev dependency)

To Reproduce
Steps to reproduce the behavior:

  1. Include Api from EosJS in a Typescript project.
  2. Build with tsc.

Expected behavior
Build succeeds

Build Output

node_modules/eosjs/dist/eosjs-api.d.ts:19:18 - error TS2304: Cannot find name 'TextEncoder'.

19     textEncoder: TextEncoder;
                    ~~~~~~~~~~~

node_modules/eosjs/dist/eosjs-api.d.ts:20:18 - error TS2304: Cannot find name 'TextDecoder'.

20     textDecoder: TextDecoder;
                    ~~~~~~~~~~~

node_modules/eosjs/dist/eosjs-api.d.ts:45:23 - error TS2304: Cannot find name 'TextEncoder'.

45         textEncoder?: TextEncoder;
                         ~~~~~~~~~~~

node_modules/eosjs/dist/eosjs-api.d.ts:46:23 - error TS2304: Cannot find name 'TextDecoder'.

46         textDecoder?: TextDecoder;
                         ~~~~~~~~~~~

node_modules/eosjs/dist/eosjs-jsonrpc.d.ts:9:28 - error TS2304: Cannot find name 'Request'.

9     fetchBuiltin: (input?: Request | string, init?: RequestInit) => Promise<Response>;
                             ~~~~~~~

node_modules/eosjs/dist/eosjs-jsonrpc.d.ts:9:53 - error TS2304: Cannot find name 'RequestInit'.

9     fetchBuiltin: (input?: Request | string, init?: RequestInit) => Promise<Response>;
                                                      ~~~~~~~~~~~

node_modules/eosjs/dist/eosjs-jsonrpc.d.ts:9:77 - error TS2304: Cannot find name 'Response'.

9     fetchBuiltin: (input?: Request | string, init?: RequestInit) => Promise<Response>;
                                                                              ~~~~~~~~

node_modules/eosjs/dist/eosjs-jsonrpc.d.ts:17:35 - error TS2304: Cannot find name 'Request'.

17         fetch?: (input?: string | Request, init?: RequestInit) => Promise<Response>;
                                     ~~~~~~~

node_modules/eosjs/dist/eosjs-jsonrpc.d.ts:17:51 - error TS2304: Cannot find name 'RequestInit'.

17         fetch?: (input?: string | Request, init?: RequestInit) => Promise<Response>;
                                                     ~~~~~~~~~~~

node_modules/eosjs/dist/eosjs-jsonrpc.d.ts:17:75 - error TS2304: Cannot find name 'Response'.

17         fetch?: (input?: string | Request, init?: RequestInit) => Promise<Response>;
                                                                             ~~~~~~~~

node_modules/eosjs/dist/eosjs-serialize.d.ts:85:18 - error TS2304: Cannot find name 'TextEncoder'.

85     textEncoder: TextEncoder;
                    ~~~~~~~~~~~

node_modules/eosjs/dist/eosjs-serialize.d.ts:86:18 - error TS2304: Cannot find name 'TextDecoder'.

86     textDecoder: TextDecoder;
                    ~~~~~~~~~~~

node_modules/eosjs/dist/eosjs-serialize.d.ts:94:23 - error TS2304: Cannot find name 'TextEncoder'.

94         textEncoder?: TextEncoder;
                         ~~~~~~~~~~~

node_modules/eosjs/dist/eosjs-serialize.d.ts:95:23 - error TS2304: Cannot find name 'TextDecoder'.

95         textDecoder?: TextDecoder;
                         ~~~~~~~~~~~

node_modules/eosjs/dist/eosjs-serialize.d.ts:235:120 - error TS2304: Cannot find name 'TextEncoder'.

235 export declare function serializeActionData(contract: Contract, account: string, name: string, data: any, textEncoder: TextEncoder, textDecoder: TextDecoder): string;
                                                                                                                           ~~~~~~~~~~~

node_modules/eosjs/dist/eosjs-serialize.d.ts:235:146 - error TS2304: Cannot find name 'TextDecoder'.

235 export declare function serializeActionData(contract: Contract, account: string, name: string, data: any, textEncoder: TextEncoder, textDecoder: TextDecoder): string;
                                                                                                                                                     ~~~~~~~~~~~

node_modules/eosjs/dist/eosjs-serialize.d.ts:237:148 - error TS2304: Cannot find name 'TextEncoder'.

237 export declare function serializeAction(contract: Contract, account: string, name: string, authorization: Authorization[], data: any, textEncoder: TextEncoder, textDecoder: TextDecoder): SerializedAction;
                                                                                                                                                       ~~~~~~~~~~~

node_modules/eosjs/dist/eosjs-serialize.d.ts:237:174 - error TS2304: Cannot find name 'TextDecoder'.

237 export declare function serializeAction(contract: Contract, account: string, name: string, authorization: Authorization[], data: any, textEncoder: TextEncoder, textDecoder: TextDecoder): SerializedAction;
                                                                                                                                                                                 ~~~~~~~~~~~

node_modules/eosjs/dist/eosjs-serialize.d.ts:239:149 - error TS2304: Cannot find name 'TextEncoder'.

239 export declare function deserializeActionData(contract: Contract, account: string, name: string, data: string | Uint8Array | number[], textEncoder: TextEncoder, textDecoder: TextDecoder): any;
                                                                                                                                                        ~~~~~~~~~~~

node_modules/eosjs/dist/eosjs-serialize.d.ts:239:175 - error TS2304: Cannot find name 'TextDecoder'.

239 export declare function deserializeActionData(contract: Contract, account: string, name: string, data: string | Uint8Array | number[], textEncoder: TextEncoder, textDecoder: TextDecoder): any;
                                                                                                                                                                                  ~~~~~~~~~~~

node_modules/eosjs/dist/eosjs-serialize.d.ts:241:177 - error TS2304: Cannot find name 'TextEncoder'.

241 export declare function deserializeAction(contract: Contract, account: string, name: string, authorization: Authorization[], data: string | Uint8Array | number[], textEncoder: TextEncoder, textDecoder: TextDecoder): Action;
                                                                                                                                                                                    ~~~~~~~~~~~

node_modules/eosjs/dist/eosjs-serialize.d.ts:241:203 - error TS2304: Cannot find name 'TextDecoder'.

241 export declare function deserializeAction(contract: Contract, account: string, name: string, authorization: Authorization[], data: string | Uint8Array | number[], textEncoder: TextEncoder, textDecoder: TextDecoder): Action;
                                                                                                                                                                                                              ~~~~~~~~~~~

Desktop (please complete the following information):

  • OS: Mac OS X 10.14.4
  • Browser: None, this issue occurs during typescript compile.
  • Version: Typescript 3.4.1

Additional context
I can see in the source file that TextEncoder and TextDecoder types seem to be global. Shouldn't they be imported from somewhere else as usual? I didn't dig much farther.

Not sure if this is related to #457 or not as there's no context in that issue about what the build problem actually was.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions