react-datetime icon indicating copy to clipboard operation
react-datetime copied to clipboard

Typescript - Installing with npm v4+ causes duplicate react types.

Open cwmacdon opened this issue 9 years ago • 4 comments

I'm Submitting a ...

[x] Bug report
[ ] Feature request
[ ] Support request

Steps to Reproduce

  1. Use npm v4.x (I've tried with 4.3.0 and 4.6.1) (not reproducible with 3.10.10)
  2. Have a package.json that has:
{
  "scripts": {
    "build": "tsc index.tsx"
  },
  "dependencies": {
      "react-datetime": "2.9.0",
      "react": "15.6.1",
      "react-dom": "15.6.1",
      "moment": "2.18.1"
  },
  "devDependencies": {
    "@types/react": "15.6.1",
    "typescript": "2.4.2"
  }
}

Expected Results

My code to compile.

Actual Results

A bunch of errors about react types not matching due to react-datetime pulling in @types/[email protected]

Minimal Reproduction of the Problem

Using the package.json above, and the following index.tsx:

import * as React from 'react';
import * as Datetime from 'react-datetime';
  1. npm i
  2. npm run build

You get a few pages of errors that look like this: node_modules/@types/react/index.d.ts(3400,19): error TS2320: Interface 'Element' cannot simultaneously extend types 'ReactElement<any>' and 'ReactElement<any>'. Named property 'type' of types 'ReactElement<any>' and 'ReactElement<any>' are not identical

Other Information (e.g. stacktraces, related issues, suggestions how to fix)

Works fine with npm v3 since v3 does not install a separate version of @types/react in /node_modules/react-datetime/node_modules/@types/react

cwmacdon avatar Aug 24 '17 22:08 cwmacdon

I'm fairly certain (but in the process of verifying) that this is due to the PR which moved @types/react from devDependencies to dependencies.

cwmacdon avatar Aug 24 '17 22:08 cwmacdon

I can confirm that this is indeed the cause.

cwmacdon avatar Aug 24 '17 22:08 cwmacdon

@cwmacdon See my questions in #409.

simeg avatar Aug 28 '17 20:08 simeg

Closing as PR #409 was merged.

simeg avatar Sep 06 '17 17:09 simeg