-
Notifications
You must be signed in to change notification settings - Fork 872
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
Update typings for Typescript 2.0 #190
Conversation
@@ -46,15 +67,11 @@ declare module ReactDatetime { | |||
*/ | |||
locale?: string; | |||
/* | |||
Whether to interpret input times as UTC or the user's local timezone. | |||
*/ | |||
utc?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this prop removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... a mistake.
|
||
//// <reference path="../moment/moment-node.d.ts" /> | ||
declare module "react-datetime" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you are using double-quotes but on L17 you are using single-quotes. Does the module declaration require double-quotes? If not I think you should change them to stay consistent :)
|
||
/* | ||
A stand-in type for Moment, this file currently has no way of guaranteeing | ||
the existence of those typings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like comments like these 😌
@@ -0,0 +1,170 @@ | |||
import * as React from 'react'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the most appropriate place for this file? If I was looking for a test file in a repo I'd check in the tests
folder (where our other tests are).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was following the recommendations from the DefinitelyTyped repository. This one doesn't necessarily apply here, I can move it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in the DefinitelyTyped readme it says
File: foo-tests.ts
Purpose: This contains sample code which tests the typings. This code does not run, but it is type-checked.
And that's what's happening in your changes, right? I didn't get that at first but yeah if strictly the typings are being tested I can see them living in the folder they're in now.
I see the typings being a separate modular thing on top of the component, so if this is the case (please confirm) then I'd say just leave it as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is definitely the case 😄
@@ -0,0 +1,170 @@ | |||
import * as React from 'react'; | |||
import { Moment } from 'moment'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is written with ES6 syntax. I prefer ES6 syntax, but none of the other files are written in this syntax. My first thought is that we should stay consistent, but at the same time this could be the first step to making everything into ES6 (which I plan on doing eventually). What are your thoughts on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer using ES6 syntax, the code is cleaner and allows for better static analysis. It is also the preferred style for Typescript.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All right, let's go with ES6.
renderMonth={ (props, month, year, selectedDate) => { | ||
return <td {...props}>{ month }</td>; | ||
} } | ||
renderYear={ ( props, year, selectedDate ) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have spaces in the arguments here that you don't have on L118 or L121 (sorry if this is a bit picky).
}, | ||
"files": [ | ||
"index.d.ts", | ||
"react-datetime-tests.tsx" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If moving the test file this reference will have to be updated as well (just a friendly reminder).
Hey @AaronAsAChimp, thanks for this awesome contribution! As you can see I added some comments to the code. These are breaking changes for people using version < 2.0 right? Is there some way to make it compatible for both, or has the whole community already embraced version 2? |
You're correct they are breaking changes. DefinitelyTyped maintains a separate branch for types-2.0 to preserve the 1.8 typings. I wasn't able to find a way to make these typings work for both. |
I am trying to figure out if we can support both v1.8 and v2.0, but I can't really see a way where we don't have to maintain two branches/repos, something I'd prefer not having to do. I am leaning towards merging this, because I like the tests and when looking at the breaking changes from 1.8 -> 2.0 there's not really a lot of them. @AaronAsAChimp what are your thoughts? Any idea on how we can support both versions? |
+1 for the TS 2.0 support. If people are still on TS 1.8, they most like are not ahead in updating their packages as well (in this case, |
@vutran that is true, but usually dependencies are marked with a carrot ( Maybe I'm overthinking this, I just don't want to answer to people asking why we broke their application. I welcome every opinon on this matter :) |
Would be great if @AaronAsAChimp could provide this via |
I would prefer we either:
Having them in both places would only lead to confusion, extra maintenance, and erroneous bug reports when someone inadvertently uses stale typings. Even if its only temporary. But Its not really up to me, its up to the maintainers and how much time they are willing to spend supporting these typings. |
@AaronAsAChimp I like the first option you are suggesting. In a few months we could look into only using v2.0+ in both DefinitelyTyped and here. @AaronAsAChimp @vutran @schickling I am reading the instructions in the README for the DefinitelyTyped repo, and I'm getting the feeling that some of you people that actually use TS can publish the 1.8 version quicker and better. Does anyone feel up for it? In what order do we do this? Can we merge this now and publish the 1.8 version to DefinitelyTyped later? Thanks so much for the help and input everyone! |
@@ -0,0 +1,171 @@ | |||
import * as React from 'react'; | |||
import { Moment } from 'moment'; | |||
import ReactDatetime = require('react-datetime'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be equal to
import * as ReactDatetime from 'react-datetime';
but it's not.. i get the following error:
[ts] Module ''react-datetime'' resolves to a non-module entity and cannot be imported using this construct.
I now get no errors in vscode using import ReactDatetime from 'react-datetime';
, but its not able to import it properly so it breaks during build
is it possible to make it work using the import * as name
syntax?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AaronAsAChimp would you be able to answer this? Thanks so much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry it took so long to reply, but I wanted to make sure I had it right. They are not equivalent.
The following is for CommonJS modules that use module.exports = Thing
. This may be an ugly way of importing, but it is not within the scope of this PR to change it. It would also massively break the way non-typescript users require the module.
import ReactDatetime = require('react-datetime');
When you have multiple named exports module.exports = { Thing: Thing }
or export class Thing { ... }
it is imported like so.
import * as ReactDatetime from 'react-datetime';
Finally, when you have a default export: export default class Thing {...}
import ReactDatetime from 'react-datetime';
You can read more here
https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AaronAsAChimp That's what I suspected. Thanks for your input, and thanks a lot for creating the PR in DefinitelyTyped.
@bovan does this make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AaronAsAChimp @simeg I suspect the documentation isn't up to date.. the require syntax is what typescript implemented before the ES6 syntax was ready.
The main issues here are:
- Editors does not allow you to type
import * as ReactDatetime from 'react-datetime';
which works - Editors allows you now to type:
import ReactDatetime from 'react-datetime';
which doesnt work.
This indicates that there is something wrong with the typings. (Also all other imports we use have no problems with the import * as- syntax, and there's a lot).
I'm sure there is a way to make the typings work without rewriting the actual code itself, unfortunately I've not had time to do further research into this.
Anyway, the problem for us is that we use tslint with "no-var-requires": true
, but i work around that with disable-line, so it's not game breaking for me, just a heads up..
About this PR - I want to wait to see what happens to the PR in DefinitelyTyped. If it gets merged I will merge this but if not I will have to think about the next step. |
Add tests for typings. Fixes issue arqex#181
Remove useless settings from tsconfig. (by recommendation of the DefinitelyTyped maintainers)
b6bdf28
to
dbaa927
Compare
With the DefinitelyTyped pull request closed. Is this ready for merge? I've updated the branch with the suggested changes. |
Sorry for the late response everyone. So we did end up with supporting both 1.8 and 2.0+ in the same repo. I am ok with that if that's the suggestion from the DefinitelyTyped people, so I'll go ahead and merge this PR. Thanks a lot everyone who contributed and a big thank you to @AaronAsAChimp for everything. |
Description
Typescript 2.0 has a new mechanism for resolving types for modules. This PR updates the typings for react-datetime to be compatible with with the latest typescript. It also includes a couple of fixes and enhancements to the typings.
viewMode
to the correct strings (or a number).timeConstraints
renderDay
,renderMonth
,renderYear
to the correct return types.inputProps
, limiting it to only those allowed on input elementsReactDatetime
to be a classMotivation and Context
Fixes issue #181. Improves compatibility with this package.
Checklist