Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ByteBuffer.js used from TypeScript #85

Open
courteous opened this issue Dec 17, 2017 · 2 comments
Open

ByteBuffer.js used from TypeScript #85

courteous opened this issue Dec 17, 2017 · 2 comments

Comments

@courteous
Copy link

I am trying to use the ByteBuffer.js in typescript. I have downloaded the typescript definitions i.e. the index.d.ts from

here

and i did the same for the Long.js
it all went well except 2 warnings

when i try to execute the following code

var bb = new ByteBuffer()
.writeIString("Hello world!")
.flip();
console.log( "base 64 encoding of the buffer: " + bb.toBase64() );

var bb = ByteBuffer.allocate(2, false, false);

I am getting the following two warnings:

WARNING in ./ts/app.ts
18:9-28 "export 'allocate' (imported as 'ByteBuffer') was not found in '../definitions/ByteBuffer'
 @ ./ts/app.ts
 @ multi ./ts/app.ts ./ts/app.ts

WARNING in ./definitions/ByteBuffer.js
Module not found: Error: Can't resolve 'long' in '/home/tito/Projects/external/definitions'
 @ ./definitions/ByteBuffer.js 30:35-50
 @ ./ts/app.ts
 @ multi ./ts/app.ts ./ts/app.ts

if I comment those lines below then the second warning about the long is gone i guess this is the same behaviour explained in the ticket number (#47 opened on May 8, 2015 by jcalfee)

    /* CommonJS */ else if (typeof require === 'function' && typeof module === "object" && module && module["exports"])
        module['exports'] = (function() {
            var Long; try { Long = require("long"); } catch (e) {}
            return factory(Long);
        })();

However i do not know what to do with the first warring why is typescript sayng that "export 'allocate' was not found. I guess this have to do with the fact that ByteBuffer.js is ready to be consumed as CommonJS and AMD module but somehow i am missing the es6 modules exports, but i might be wrong. Any ideas about this?

@dcodeIO
Copy link
Member

dcodeIO commented Dec 17, 2017

Usually you'd simply add long and bytebuffer like so:

npm install long bytebuffer

and use the definitions in development:

npm install --save-dev @types/long @types/bytebuffer

Afterwards, something like import * as ByteBuffer from "bytebuffer" should just work. Note that these definitions have been created by a 3rd party.

@courteous
Copy link
Author

Hello Daniel, many thanks for the quick response. Indeed i forgot to do "npm install long" . Many thanks for the quick feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants