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

fix TS module resolution #123

Closed
wants to merge 2 commits into from
Closed

Conversation

bbenezech
Copy link

I couldn't use npm Reselect typings as I do with eg Immutable.js
TS would not find the module.
It turns out you need to declare a module whose name match exactly the import's name, "" included.
I tested it, it works®

A good reference: https://github.com/facebook/immutable-js/blob/master/dist/immutable.d.ts

I couldn't use npm Reselect typings as I do with eg Immutable.js
TS would not find the module.
It turns out you need to declare a module whose name match exactly the import's name, "" included.
I tested it, it works®

A good reference: https://github.com/facebook/immutable-js/blob/master/dist/immutable.d.ts
@coveralls
Copy link

coveralls commented Apr 28, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling a2c7eb1 on bbenezech:patch-1 into 3ef252f on reactjs:master.

@coveralls
Copy link

coveralls commented May 9, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling e7b4adb on bbenezech:patch-1 into 3ef252f on reactjs:master.

@codecov-io
Copy link

Current coverage is 100%

Merging #123 into master will not change coverage

@@           master   #123   diff @@
====================================
  Files           1      1          
  Lines          47     47          
  Methods         0      0          
  Messages        0      0          
  Branches        0      0          
====================================
  Hits           47     47          
  Misses          0      0          
  Partials        0      0          

Powered by Codecov. Last updated by 3ef252f...c72c401

@threehams
Copy link
Collaborator

Using TypeScript 1.8, with the following import syntax and .tsconfig, I can compile without problems on master, but see errors when using the changes in your branch:

import { createSelector } from 'reselect';

or

import reselect = require('reselect');

.tsconfig

{
  "compilerOptions": {
    "allowJs": true,
    "experimentalDecorators": true,
    "jsx": "preserve",
    "module": "commonjs",
    "outDir": "tsDist",
    "target": "es2015",
    "moduleResolution": "node"
  },
  "exclude": [
    "node_modules",
    "server.js",
    "serverConfig.js",
    "webpack.config.js"
  ]
}

With this pull request, I see an error:

error TS2656: Exported external package typings file 'node_modules/reselect/src/reselect.d.ts' is not a module. Please contact the package author to update the package definition.

Can you give information on your environment - TS version, .tsconfig settings, and import / require syntax?

@bbenezech
Copy link
Author

@threehams Does it work with immutable ?

I just basically used their project as a template as they should know better.

@threehams
Copy link
Collaborator

Again, can you post reproduction steps and version/environment/code? The ability to read definition files from node_modules was added in Typescript 1.6, so version matters a lot here, as well as es5/6 target, module setting, whether you're using Babel in addition to Typescript, etc.

Immutable creates a module, exports everything from that, then re-exports it using the final string name. This makes it backwards-compatible with 1.5 and earlier when used outside node_modules, but I don't think we're not worried about doing that here. If we're targeting 1.6+, it's simpler to use top-level exports and avoid declaring modules at all:

// Type definitions for reselect v2.0.2

export type Selector<TInput, TOutput> = (state: TInput, props?: any) => TOutput;

export function createSelector<TInput, TOutput, T1>(selector1: Selector<TInput, T1>, combiner: (arg1: T1) => TOutput): Selector<TInput, TOutput>;
export function createSelector<TInput, TOutput, T1, T2>(selector1: Selector<TInput, T1>, selector2: Selector<TInput, T2>, combiner: (arg1: T1, arg2: T2) => TOutput): Selector<TInput, TOutput>;
...etc.

Information on writing definition files can be really tricky to find, and a lot of it is buried in comments in issues and pull requests.

microsoft/TypeScript#247 (comment)

@ellbee
Copy link
Collaborator

ellbee commented Jul 30, 2016

As we can't reproduce this, I am going to close due to inactivity.

@ellbee ellbee closed this Jul 30, 2016
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

Successfully merging this pull request may close these issues.

5 participants