Paul
Paul

Reputation: 4530

How do I add a new type to DefinitelyTyped that has external dependencies?

I'm having trouble figuring out how to add a new type to DefinitelyTyped when it has external dependencies. I cannot get the tests to pass because modules are not able to be found unless I add a package.json to the folder, but the linter does not pass because the packages are not whitelisted.

Here is the pull request:

https://github.com/DefinitelyTyped/DefinitelyTyped/pull/21581

// index.d.ts

import {
     ApolloClient,
     ObservableQuery,
     WatchQueryOptions,
     ApolloError
} from 'apollo-client';

https://github.com/DefinitelyTyped/DefinitelyTyped/pull/21581/files#diff-bedcd6706b6ae7a6f6df5951737dcc31R12

Also in my tests there are some other dependencies I need so that I can actually use it, but devDependencies is not allowed by the linter.

So without a package.json, I get an error during the tests that say "module not found 'mob-apollo' -- which makes sense.

So I added a package.json:

{
    "private": true,
    "dependencies": {
        "apollo-client": "^2.0.0",
        "graphql-tag": "^2.0.0",
        "mobx": "^3.0.0"
    }
}

Now I get an error during the linter:

Error: In /home/travis/build/DefinitelyTyped/DefinitelyTyped/types/mobx-apollo/package.json: Dependency apollo-client not in whitelist; please make a pull request to types-publisher adding it.

However, if you look at the whitelist, it is very small, so this can't be the proper way to address this... is it? I'd imagine if you had to whitelist for every package that had a dependency then this list would be huge.

https://github.com/Microsoft/types-publisher/blob/master/dependenciesWhitelist.txt

So what should I do here?

Upvotes: 3

Views: 963

Answers (1)

alechill
alechill

Reputation: 4502

External package dependencies are only needed for packages that define their own types, all others will be found by the compiler directly from the DT repo via "typeRoots": ["../"] in tsconfig.json, which is why the whitelist is short - in general most still come from DT itself.

When importing in *.d.ts and the test files, the compiler is only importing the type info rather than generating JS, and so the actual packages are not needed, only the definitions - if these are from external package then that package is a legitimate dependency, but still no JS will be generated, it is a compiler test only

In that case it should be perfectly valid to raise a PR adding apollo-client to the whitelist as it is written in TS and is distributed with its own definitions

Regarding the other dependencies, it looks like they are only for the test case, in which you do more than test just your own package, but also test its integration in context of MobX, which may be overkill considering you will also need to bring in these packages (if they define their own types - mobx) or write new defs for the others that have no type defs of their own or already in DT (like graphql-tag). You could keep it simple and keep those out of the test case, which would also mean less maintenance overhead from you needing to keep these up to date too

Upvotes: 3

Related Questions