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

Typescript Typings are out of date #101

Closed
pradyuman opened this issue Jul 30, 2017 · 7 comments · Fixed by #159
Closed

Typescript Typings are out of date #101

pradyuman opened this issue Jul 30, 2017 · 7 comments · Fixed by #159

Comments

@pradyuman
Copy link

Is it possible for you guys to update the existing typings for Typescript?
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/e5ed4fc91679670a415f2534005ef8d67ec2189e/types/universal-router/index.d.ts

There were breaking API changes in v3 so it would be nice to have the typings reflect those.

Thanks!

@dangmai
Copy link

dangmai commented Aug 13, 2017

I'm trying to update the typing for universal-router to the newest version, and there's an annoying issue I'd like to bring up. Right now the distributed library is a CommonJS module, not an ES6 module, and thus we can't do something like this in Typescript:

import Router from 'universal-router';

We have to do this instead:

import Router = require('universal-router');

This is because a CommonJS module exports the Router class instead of a default that points to the Router class (which is what Typescipt expects). Note that a transpiler like Babel does some interop magic behind the scene to accommodate this (see microsoft/TypeScript#11179) which Typescript currently does not (proposal to fix this is tracked at microsoft/TypeScript#16093)

Is there a way for universal-router to export a module that is compliant with both CommonJS and ES6 modules? Here's how some other libraries are doing it - microsoft/TypeScript#16093 (comment)

@frenzzy
Copy link
Member

frenzzy commented Aug 14, 2017

Maybe "module": "main.mjs" field in package.json could solve this?

@anantoghosh
Copy link

@dangmai You can use the allowSyntheticDefaultImports compiler option in your tsconfig

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true
    ...

@frenzzy
Copy link
Member

frenzzy commented Nov 28, 2017

Flow types: flow-typed/flow-typed#1596

@gytisgreitai
Copy link

Any work around ? the import Router = require('universal-router'); does not seem to work with ts 2.6.x

Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.

@frenzzy
Copy link
Member

frenzzy commented Jan 19, 2018

@gytisgreitai can you try require('universal-router/main') ?

@gytisgreitai
Copy link

gytisgreitai commented Jan 19, 2018

no, same error.
If I dos something like let UniversalRouter = require('universal-router/main'); just sets UniversalRouter to a js file (a plain string)

Same goes for import * as UniversalRouter from 'universal-router/main';

I'm using react-creat-app-ts so maybe there is something in between. For now I've simply resorted to unpkg since this is a small intranet project.

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

Successfully merging a pull request may close this issue.

5 participants