date-io: Type augmentations included in published package fail downstream compilation

From https://github.com/mui-org/material-ui-pickers/issues/1074#issuecomment-504511836

I’ll work on a PR, I’m going to try a couple of things, but worst case is we need to not publish the type dir in the package as it does not satisfy the compiler.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 2
  • Comments: 22 (9 by maintainers)

Commits related to this issue

Most upvoted comments

I’m trying to use the pickers with the @date-io/luxon package and tsc is failing:

node_modules/@material-ui/pickers/typings/date.d.ts:1:26 - error TS2307: Cannot find module '@date-io/type'.

1 import { DateType } from '@date-io/type';
                           ~~~~~~~~~~~~~~~

node_modules/@material-ui/pickers/views/Year/YearView.d.ts:2:26 - error TS2307: Cannot find module '@date-io/type'.

2 import { DateType } from '@date-io/type';

I’m not allowed to commit to our code base with tsc errors present. Please fix the typing issue.

Closing that. Here is a repo where auto-linked @date-io/type module works like a charm

Basically the problem is same, We have a package where we are using @material-ui/pickers, with @date-io/moment. This package builds fine because, we have import MomentUtils from '@date-io/moment. `/** @jsx jsx */ import { jsx } from ‘@emotion/core’; import React from ‘react’; import { IDatePicker } from ‘./interfaces’; import { CustomDatePicker, DatePickerContainer } from ‘./DatePicker.style’;

import moment, { Moment } from ‘moment’; import MomentUtils from ‘@date-io/moment’; import { DatePicker as DateSelector, MuiPickersUtilsProvider } from ‘@material-ui/pickers’;

export const DatePicker = (props: IDatePicker): React.ReactElement => { const [isOpen, setIsOpen] = React.useState<boolean>(false); return ( <DatePickerContainer css={CustomDatePicker}> <MuiPickersUtilsProvider utils={MomentUtils} libInstance={moment}> <DateSelector open={isOpen} onOpen={(): void => setIsOpen(true)} onClose={(): void => setIsOpen(false)} value={props.selectedDate} onChange={(date: Moment): void => props.handleDateChange(moment(date).toDate())} /> </MuiPickersUtilsProvider> </DatePickerContainer> ); }; If you look at the peer dependency section, .... }, “peerDependencies”: { “moment”: “2.x”, “react”: “16.x”, “react-dom”: “16.x”, “@date-io/moment”: “1.3.x”, “@material-ui/pickers”: “3.2.x” }, …`

When we consume this package in another package, i am getting typescript error like this,

ttsc -p tsconfig.json --noEmit

node_modules/@material-ui/pickers/typings/date.d.ts:1:26 - error TS2307: Cannot find module ‘@date-io/type’.

1 import { DateType } from ‘@date-io/type’; ~~~~~~~~~~~~~~~

node_modules/@material-ui/pickers/views/Year/YearView.d.ts:2:26 - error TS2307: Cannot find module ‘@date-io/type’.

2 import { DateType } from ‘@date-io/type’;

In order to get around this problem, i had to follow suggested comment, https://github.com/dmtrKovalenko/date-io/issues/52#issuecomment-631844736 . This is ugly because we had to change the tsconfig to all the consumer packages.

..... "noUnusedLocals": true, "resolveJsonModule": true }, "include": ["src", "node_modules/@date-io/moment/type/index.d.ts"] }