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

1.3.1 TypeScript example doesn't work with Browserify #186

Closed
dpogue opened this issue Mar 8, 2016 · 4 comments
Closed

1.3.1 TypeScript example doesn't work with Browserify #186

dpogue opened this issue Mar 8, 2016 · 4 comments

Comments

@dpogue
Copy link
Contributor

dpogue commented Mar 8, 2016

The TypeScript code is set up assuming ES6 modules with a default export are used, but in practice dexie.js does not use a default export.

Trying to subclass Dexie then fails:

import Dexie from 'dexie';

class MyDB extends Dexie {
  // ...
}

Generates the following JS:

var dexie_1 = require('dexie');

var MyDB = (function(_super) {
  __extends(this, _super);
  // ...
})(dexie_1.default);

When running in Browserify, dexie_1.default is undefined, leading to an error when the __extends helper tries to inherit the prototype.

@dfahlander
Copy link
Collaborator

Dexie does indeed default export in its source version at src/Dexie.js and in dist/dexie.es6.js. The transpiled UMD module (dexie.js) may not do this though, but if you target your typescript to es6 and then use babel to get the es5 code it should work.

In my typescript sample, I use a setup with tsc + babel + webpack and that works just fine. Haven't tested the setup with tsc + babel + browserify, but I suppose that combo is common too.

If it's a problem with compiling from ts-->es5 directly with browserify, I must fix it because that would be a common thing to use. Any suggestions?

@dfahlander
Copy link
Collaborator

Seems tsc behaves differently when targeting es5.

microsoft/TypeScript#5285

I've updated the README.md to clarify that you need to target es6 for the sample to work.

@dfahlander
Copy link
Collaborator

Ok, so now I've found a workaround that makes dexie.d.ts work both when tsc is targeting es5 and es6. SImply setting Dexie.default = Dexie makes it work in both cases and does not interfere with anything else.

@dpogue
Copy link
Contributor Author

dpogue commented Mar 9, 2016

It's working now. Thanks!

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