Skip to content
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

Setup TS tests #418

Merged
merged 1 commit into from Mar 4, 2019
Merged

Setup TS tests #418

merged 1 commit into from Mar 4, 2019

Conversation

Andarist
Copy link
Contributor

I've added infrastructure to test TS typings by possible use cases which should prevent regressions in the future (once more tests get added ofc)

@erikras
Copy link
Member

erikras commented Jan 30, 2019

This pull request introduces 2 alerts when merging 90a471e into 65a239b - view on LGTM.com

new alerts:

  • 2 for Unused variable, import, function or class

Comment posted by LGTM.com

@Andarist
Copy link
Contributor Author

Andarist commented Jan 30, 2019

@erikras LGTM report is actually an expected result (those rules should be disabled for .ts files as their purpose is to test interfaces and not to actually be executed), but LGTM setting is not in this repo (I think) and thus I cannot fix it :<

As to Travis - this is currently blocked by microsoft/dtslint#190

@codecov
Copy link

codecov bot commented Feb 20, 2019

Codecov Report

Merging #418 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #418   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          10     10           
  Lines         207    207           
  Branches       61     61           
=====================================
  Hits          207    207

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 768a476...029914a. Read the comment docs.

@erikras
Copy link
Member

erikras commented Feb 20, 2019

This pull request introduces 2 alerts when merging 029914a into 768a476 - view on LGTM.com

new alerts:

  • 2 for Unused variable, import, function or class

Comment posted by LGTM.com

@Andarist
Copy link
Contributor Author

@erikras new version of dtslint got published, this PR should be ready to merge now. Would be good to tweak LGTM setup to ignore rules such as no-unused-vars in typescript directory

@erikras erikras merged commit 9828131 into final-form:master Mar 4, 2019
@erikras
Copy link
Member

erikras commented Mar 4, 2019

Published in v4.1.0

reactFinalForm: FormApi;
}

export interface FieldRenderProps<T extends HTMLElement> {
Copy link

@pokonski pokonski Mar 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Andarist, can you tell why FieldRenderProps now requires the argument now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Truth to be told - I don't know. I don't recall making this change, but I've looked through git history and my local reflog and it seems I was indeed the one making it.

That being said the change makes sense to me FieldRenderProps["input"] is a set of closely related things, the generic should constraint the whole thing and not the specific handlers separately, because you could call them with different input type.

Could you paste in the example code which broke by this change? Could you describe why do you think this change should be reverted? We could now start writing tests to be sure such changes won't affect existing codebases.

However it's somewhat a known problem (and I dont think we can really improve on that as community) for libraries shipping type definitions - personally I dont think that typings change should require a major bump, it would be too restrictive. So the best approach is to lock your dependencies and update frequently.

@Andarist Andarist deleted the setup-ts-tests branch March 6, 2019 13:11
@pokonski
Copy link

pokonski commented Mar 6, 2019

I just started using the library and noticed some TypeScript examples of how people write their components for fields and neither had the argument prior to the latest version of the react-final-form.

Is the argument really needed if it's not used for anything inside the interface?

@Andarist
Copy link
Contributor Author

Andarist commented Mar 6, 2019

Is the argument really needed if it's not used for anything inside the interface?

But it's used very much so - in event handlers declarations, i.e. here

Check out what this generic parameter gives u - https://github.com/final-form/react-final-form/pull/439/files#diff-c9d158e9961d9803798bff495584efabR1 . I could potentially add a default but it would be = HTMLElement, dunno if that would be useful.

@pokonski
Copy link

pokonski commented Mar 6, 2019

@Andarist ah indeed! It still feels a bit weird to have to specify it as an argument to those props because it basically can be either an input or a select, right?

For example Formik has it set to any:
https://github.com/jaredpalmer/formik/blob/02b8911f72554495afa18ddb87eaf1f4296d97ff/src/types.tsx#L140

as does ReduxForm:

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/792f0a463bdc976ab1a22f405f183e2409df389d/types/redux-form/lib/Field.d.ts#L80

@Andarist
Copy link
Contributor Author

Andarist commented Mar 6, 2019

@Andarist ah indeed! It still feels a bit weird to have to specify it as an argument to those props because it basically can be either an input or a select, right?

It could also be a textarea and probably (but not sure) a custom element (as in webcomponent).

In my opinion TS's goal is to type check our programs and it can only do that if we give it appropriate & strict hints. Using any anywhere is the opposite of safety and IMHO we should strive to avoid it at all costs - personally I try to use it only sometimes in very local places, casting it back to something conrete as soon as possible.

We could provide both versions under the same name using conditional types but it seems weird to me to allow non-strict versions because it probably will get used more frequently than strict one due to lack of exposure.

That being said we have to take developer ergonomics into account, I'm far from TS expert and I don't exactly know what are conventions used currently by the community, so would love having more people discussing this.

@lock
Copy link

lock bot commented Apr 5, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants