Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions types/react-slick/react-slick-tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ const defaultSettings: Settings = {
};

class SliderTest extends React.Component {
private slider: Slider;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IMO this can be written that way, testing/asserting expected types onlyl, more like every day usage (otherwise it starts to look like !newest !Angular with !latest !TS):

diff --git a/types/react-slick/react-slick-tests.tsx b/types/react-slick/react-slick-tests.tsx
index 0813300bda..d0f393fe01 100644
--- a/types/react-slick/react-slick-tests.tsx
+++ b/types/react-slick/react-slick-tests.tsx
@@ -67,12 +67,15 @@ const defaultSettings: Settings = {
 };
 
 class SliderTest extends React.Component {
-  private slider: Slider | null = null;
+  private slider: Slider;
   render() {
     return <div>
       <Slider
         {...defaultSettings}
-        ref={(component: Slider | null) => { this.slider = component; }}
+        ref={(component: Slider | null) => {
+            component; // $ExpectType Slider | null
+            this.slider = component!;
+        }}
       >
         <div><h3>1</h3></div>
         <div><h3>2</h3></div>
@@ -82,9 +85,9 @@ class SliderTest extends React.Component {
         <div><h3>6</h3></div>
       </Slider>
       <div style={{ textAlign: "center" }}>
-        <button className="button" onClick={(event) => { this.slider!.slickPrev(); }}>Previous</button>
-        <button className="button" onClick={(event) => { this.slider!.slickNext(); }}>Next</button>
-        <button className="button" onClick={(event) => { this.slider!.slickGoTo(1); }}>First</button>
+        <button className="button" onClick={(event) => { this.slider.slickPrev(); }}>Previous</button>
+        <button className="button" onClick={(event) => { this.slider.slickNext(); }}>Next</button>
+        <button className="button" onClick={(event) => { this.slider.slickGoTo(1); }}>First</button>
       </div>
     </div>;
   }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yes, those are optional, on @eps1lon discretion

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

But this would hide that this.slider.slickPrev is possibly null at runtime. With the ! we have at least some indication that we're cheating here.

I would prefer if we can merge this now, and then you can change the test later if you wish. Otherwise I'd have to change this PR and wait another 2 weeks for this to get merged. For something that, IMO, is just a stylistic preference.

private slider: Slider | null = null;
render() {
return <div>
<Slider
{...defaultSettings}
ref={(component: Slider) => { this.slider = component; }}
ref={(component: Slider | null) => { this.slider = component; }}
>
<div><h3>1</h3></div>
<div><h3>2</h3></div>
Expand All @@ -82,9 +82,9 @@ class SliderTest extends React.Component {
<div><h3>6</h3></div>
</Slider>
<div style={{ textAlign: "center" }}>
<button className="button" onClick={(event) => { this.slider.slickPrev(); }}>Previous</button>
<button className="button" onClick={(event) => { this.slider.slickNext(); }}>Next</button>
<button className="button" onClick={(event) => { this.slider.slickGoTo(1); }}>First</button>
<button className="button" onClick={(event) => { this.slider!.slickPrev(); }}>Previous</button>
<button className="button" onClick={(event) => { this.slider!.slickNext(); }}>Next</button>
<button className="button" onClick={(event) => { this.slider!.slickGoTo(1); }}>First</button>
</div>
</div>;
}
Expand Down