added declarations for react-router-navigation packages#23114
Conversation
|
@kaoDev Thank you for submitting this PR! Because this is a new definition, a DefinitelyTyped maintainer will be reviewing this PR in the next few days once the Travis CI build passes. In the meantime, if the build fails or a merge conflict occurs, I'll let you know. Have a nice day! |
|
@kaoDev One or more reviewers has requested changes. Please address their comments. I'll be back once they sign off or you've pushed new commits. Thank you! |
| oldBuild?: Item[] | ||
| ) => Item[]; | ||
|
|
||
| // eslint-disable-next-line |
There was a problem hiding this comment.
Remove this line -- we use tslint and not eslint
There was a problem hiding this comment.
oh yes of course, this line slipped in from the original code
| StyleProp, | ||
| ViewStyle | ||
| } from "react-native"; | ||
| import { TabStack, renderSubView } from "react-router-navigation-core"; |
There was a problem hiding this comment.
Could you try to narrow this test down to just using these two things? This seems to mostly be testing other react packages.
There was a problem hiding this comment.
yes I will do, for this test I just copied one of the Lib files which use the core-lib
| } | ||
| } | ||
|
|
||
| export default BottomNavigation; |
| { | ||
| "extends": "dtslint/dt.json", | ||
| "rules": { | ||
| "interface-over-type-literal": false, |
There was a problem hiding this comment.
It would be better to just use the default tslint rules instead of adding exceptions for some packages.
There was a problem hiding this comment.
this also has to do with my preference of types over interfaces, but if there are good arguments for the different rules I can get convinced 😄
There was a problem hiding this comment.
Intersecting two types never fails, while interfaces bring more guarantees.
Also, when you use an interface we are able to use the type name in more places.
type T = { a: number; x: number };
type U = T & { b: number; x: string };
declare const u: U;
u.a; // (property) a: number
u.b; // (property) b: number
u.x; // (property) x: number & string
interface I { a: number; x: number; }
interface J extends I { b: number; x: string; } // Error, bad override of 'x'
declare const j: J;
j.a; // (property) I.a: number
j.b; // (property) J.b: number
j.x; // (property) J.x: stringThere was a problem hiding this comment.
okay I see the benefit with the bad override, thank you for the explanation. But still don't know if I'm completely convinced, because interfaces allow declaration merging what I think is quite dirty, because it spreads the definition to different places.
Also the behavior of intersection types is very close to the behavior of object merging in JS, so I think of it as the typed equivalent of Object.assign
type T3 = T1 & T2
const a: T1
const b: T2
const c: T3 = Object.assign(a, b)But all arguments aside in this specific case I still want to stay with types instead of interfaces just to stay closer to the original code in flowType.
https://github.com/LeoLeBras/react-router-navigation/blob/master/packages/react-router-navigation/src/TypeDefinitions.js
There was a problem hiding this comment.
Unless the value is actually number & string at runtime, it's not more accurate to the runtime behavior! The compiler and language service work best on named over anonymous types -- please stick to the DefinitelyTyped lint rules.
There was a problem hiding this comment.
hmm you are making it more difficult than it should be to contribute type declarations.
As I already said the main reason to use types instead of interfaces is that the original code written in FlowType also uses types instead of interfaces.
If I would use interfaces everytime the original code changes there will be the transfer from type to interface again. By using types it is almost just copy and paste.
There was a problem hiding this comment.
another argument to stay with types for this lib is, that the implementation of intersection types in flow is the same as in typescript, with the same pitfalls (https://flow.org/en/docs/types/intersections/#toc-intersections-of-object-types)
So with interfaces instead of types there would be a real difference to the original typings
| */ | ||
|
|
||
| export type TabSubViewProps = any; | ||
| // SceneRendererProps & |
There was a problem hiding this comment.
because it is taken directly from the flow-types of the package. I hope those types will get finalized when the lib gets beyond RC state
| strict?: boolean; | ||
| }; | ||
|
|
||
| export type Card = RouteProps & { |
There was a problem hiding this comment.
It's better to use interface inheritance instead of intersection types.
There was a problem hiding this comment.
what are the exact benefits of interfaces vs types? I personally prefer the type keyword because it is close to other functional languages.
|
🔔 @Andy-MS - Thanks for your review of this PR! Can you please look at the new code and update your review status if appropriate? |
|
Merged with manual lint fix. In future please update code to conform to DefinitelyTyped standards instead of just pasting code from other programming languages. |
|
for me the main target for declarations is to be consistent with the described code, so in this case it's not about being able to copy the original code written in FlowType but to be consistent. |
Please fill in this template.
npm run lint package-name(ortscif notslint.jsonis present).Select one of these and delete the others:
If adding a new definition:
dts-gen --dt, not by basing it on an existing project.tslint.jsonshould be present, andtsconfig.jsonshould havenoImplicitAny,noImplicitThis,strictNullChecks, andstrictFunctionTypesset totrue.this PR contains declarations for 2 packages from https://github.com/LeoLeBras/react-router-navigation
the lib owner has suggested to put the declarations into the DefinitelyTyped Repo winoteam/react-router-navigation#36