Skip to content

Commit

Permalink
Enable TypeScript's strict mode to fix bugs and preemptively catch ne…
Browse files Browse the repository at this point in the history
…w ones (#50)

* Fix implicit any type error

* build(tsconfig): Enable strict mode to enforce good practices

* fix: Handle strict mode typescript errors
  • Loading branch information
vhfmag authored and jaredpalmer committed Nov 26, 2017
1 parent 59404c6 commit 6e192ad
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 15 deletions.
12 changes: 6 additions & 6 deletions src/DeviceMotion/DeviceMotion.tsx
Expand Up @@ -10,10 +10,10 @@ import { SharedRenderProps } from '../types';
import { isEmptyChildren } from '../utils';

export interface DeviceMotionProps {
acceleration: DeviceAcceleration;
accelerationIncludingGravity: DeviceAcceleration;
rotationRate: DeviceRotationRate;
interval: number;
acceleration: DeviceAcceleration | null;
accelerationIncludingGravity: DeviceAcceleration | null;
rotationRate: DeviceRotationRate | null;
interval: number | null;
}

export class DeviceMotion extends React.Component<
Expand Down Expand Up @@ -49,11 +49,11 @@ export class DeviceMotion extends React.Component<
};

componentDidMount() {
window.addEventListener('deviceMotion', this.handleDeviceMotion, true);
window.addEventListener('devicemotion', this.handleDeviceMotion, true);
}

componentWillUnmount() {
window.removeEventListener('deviceMotion', this.handleDeviceMotion);
window.removeEventListener('devicemotion', this.handleDeviceMotion);
}

render() {
Expand Down
4 changes: 2 additions & 2 deletions src/Mailto.tsx
Expand Up @@ -34,8 +34,8 @@ export const Mailto: React.SFC<MailtoProps> = ({
<a
href={`mailto:${email}?${qs.stringify({
subject,
cc: cc.join(', '),
bcc: bcc.join(', '),
cc: cc && cc.join(', '),
bcc: bcc && bcc.join(', '),
body,
})}`}
{...props}
Expand Down
4 changes: 2 additions & 2 deletions src/Scroll/Scroll.tsx
Expand Up @@ -24,15 +24,15 @@ export class Scroll extends React.Component<
ScrollConfig & SharedRenderProps<ScrollProps>,
ScrollProps
> {
static defaultProps = {
static defaultProps: Partial<ScrollConfig> = {
throttle: 100,
};

state: ScrollProps = { x: 0, y: 0 };

handleWindowScroll = throttle(() => {
this.setState({ x: window.scrollX, y: window.scrollY });
}, this.props.throttle);
}, this.props.throttle!);

componentDidMount() {
this.handleWindowScroll();
Expand Down
6 changes: 3 additions & 3 deletions src/WindowSize/WindowSize.tsx
Expand Up @@ -23,15 +23,15 @@ export class WindowSize extends React.Component<
WindowSizeConfig & SharedRenderProps<WindowSizeProps>,
WindowSizeProps
> {
static defaultProps = {
debounce: 100,
static defaultProps: Partial<WindowSizeConfig> = {
throttle: 100,
};

state: WindowSizeProps = { width: 0, height: 0 };

handleWindowSize = throttle(() => {
this.setState({ width: window.innerWidth, height: window.innerHeight });
}, this.props.throttle);
}, this.props.throttle!);

componentDidMount() {
this.handleWindowSize();
Expand Down
2 changes: 1 addition & 1 deletion src/utils/debounce.ts
Expand Up @@ -17,7 +17,7 @@
*/
export const debounce = (func: Function, wait: number, immediate?: boolean) => {
let timeout: any;
return function() {
return function(this: any) {
var context = this,
args = arguments;
var later = function() {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/throttle.ts
Expand Up @@ -6,7 +6,7 @@
* @param wait time
*/

export function throttle(func: Function, wait: Number) {
export function throttle(this: any, func: Function, wait: Number) {
let timeout: number | null = null;
let callbackArgs: IArguments | null = null;
const context = this;
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Expand Up @@ -19,6 +19,7 @@
"removeComments": true,
"sourceMap": true,
"pretty": true,
"strict": true,

"stripInternal": true,
"target": "es5",
Expand Down

0 comments on commit 6e192ad

Please sign in to comment.