Skip to content

Unable to override typings #11517

Closed
Closed
@mgroenhoff

Description

@mgroenhoff

I'm having trouble redirecting the lookup of certain typings to a custom directory. The reason i want this is because when i find an error in an at-types module and i issue a pull-request, it usually takes a while before it is reviewed, merged and published etc. In the meanwhile i want to use the version that i modified until the fix is merged and i can depend on the original at-types module again.

I would copy the @types/<package-name>/index.d.ts to a custom directory and edit that. Then i would remove the dependency by removing it a-la npm rm @types/<package-name>

In the case where no other packages depend on that same at-types package this works fine but the problem surfaces when one does depend on that same module that i edited.

TypeScript Version: 2.0.3

Let's say we have a project called temporary-types.

temporary-types/package.json

{
  "name": "temporary-types",
  "version": "0.0.1",
  "main": "lib/index.js",
  "devDependencies": {
    "typescript": "^2.0.3"
  },
  "dependencies": {
    "@types/react-dom": "^0.14.17",
    "react": "^15.3.2",
    "react-dom": "^15.3.2"
  }
}

temporary-types/tsconfig.json

{
    "compilerOptions": {
        "baseUrl": "",
        "paths": {
            "*": [
                "types/*"
            ]
        },
        "target": "es5"
    },
    "files": [
        "index.ts"
    ]
}

temporary-types/index.ts

import * as React from "react";
import * as ReactDOM from "react-dom";

ReactDOM.render(React.DOM.div("Hello, world!"), document.body);

temporary-types/types/react/index.ts

// This file can be modified but for simplicity contains the exact same contents as the original @types/react/index.d.ts file.

If i compile this i get the following result:

$ ./node_modules/.bin/tsc
node_modules/@types/react/index.d.ts(7,21): error TS2300: Duplicate identifier 'React'.
types/react/index.d.ts(7,21): error TS2300: Duplicate identifier 'React'.
$ ./node_modules/.bin/tsc --traceResolution | grep @types/react/index.d.ts
'package.json' has 'typings' field 'index.d.ts' that references 'C:/Source/temporary-types/node_modules/@types/react/index.d.ts'.
File 'C:/Source/temporary-types/node_modules/@types/react/index.d.ts' exist - use it as a name resolution result.
======== Type reference directive 'react' was successfully resolved to 'C:/Source/temporary-types/node_modules/@types/react/index.d.ts', primary: true. ========
======== Resolving module 'global' from 'C:/Source/temporary-types/node_modules/@types/react/index.d.ts'. ========
node_modules/@types/react/index.d.ts(7,21): error TS2300: Duplicate identifier 'React'.

I guess it could work if i do the same thing to all the packages that depend on the modified package and then recursively but this is not a solution.

PS: This issue probably needs a better title.

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions