-
Notifications
You must be signed in to change notification settings - Fork 489
Enabling various Typescript Compile Options (strict null checks, etc.) #280
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
Conversation
deregtd
commented
Sep 18, 2017
@deregtd, |
src/common/Types.ts
Outdated
type: React.ComponentClass<P>; | ||
props: P; | ||
} | ||
// interface Element<P> { |
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 not remove?
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.
It was probably wanted by someone originally. Gets compiled away.
src/macos/Input.ts
Outdated
@@ -7,7 +7,7 @@ | |||
* MacOS implementation of Input interface. | |||
*/ | |||
|
|||
import RN = require('react-native'); | |||
//import RN = require('react-native'); |
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 not remove?
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.
When they build this component, they'll want this line back.
src/android/Text.tsx
Outdated
protected _getStyles(): Types.TextStyleRuleSet | Types.TextStyleRuleSet[] { | ||
return Styles.combine<Types.TextStyle>([_styles.defaultText, this.props.style]); | ||
protected _getStyles(): Types.StyleRuleSetRecursiveArray<Types.TextStyleRuleSet> { | ||
return _.compact([_styles.defaultText, this.props.style]); |
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 are you calling compact here? It's fine to have undefined or null values in the styles that are sent to RN.
src/common/Types.ts
Outdated
@@ -488,7 +488,7 @@ export interface ImagePropsShared extends CommonProps { | |||
resizeMethod?: 'auto' | 'resize' | 'scale'; // Android only | |||
title?: string; | |||
|
|||
onLoad?: (size: Dimensions) => void; | |||
onLoad?: (size: OptionalDimensions) => void; |
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 are these fields optional? Are there circumstances where RN can't hand back valid dimensions? I'd prefer if these are non-optional. Otherwise it complicates the logic in all components that use this callback.
@@ -938,7 +938,7 @@ export interface PopupOptions { | |||
// anchor has been pressed. | |||
// IMPORTANT NOTE: This handler may be called when the component is | |||
// already unmounted as it uses a time delay to accommodate a fade-out animation. | |||
onAnchorPressed?: (e: RX.Types.SyntheticEvent) => void; | |||
onAnchorPressed?: (e?: RX.Types.SyntheticEvent) => void; |
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 is this parameter optional? Seems like it should be required.
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.
talked offline
src/common/Types.ts
Outdated
type: React.ComponentClass<P>; | ||
props: P; | ||
} | ||
// interface Element<P> { |
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 this is unused, you can delete it.
src/common/Types.ts
Outdated
@@ -1115,6 +1115,10 @@ export type Dimensions = { | |||
width: number; | |||
height: number; | |||
}; | |||
export type OptionalDimensions = { |
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.
See note above. I don't think these fields should be optional.
src/native-common/GestureView.tsx
Outdated
|
||
const timeStamp = this._getEventTimestamp(e); | ||
|
||
return (timeStamp - initialTimeStamp <= _tapDurationThreshold && | ||
this._calcDistance(initialPageX - e.pageX, initialPageY - e.pageY) <= _tapPixelThreshold); | ||
this._calcDistance(initialPageX - (e.pageX || 0), initialPageY - (e.pageY || 0)) <= _tapPixelThreshold); |
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.
For these types of events, we're guaranteed that pageX and pageY are defined. So you could keep the code as is or change it to e.pageX!!!, etc.
src/web/AlertModalContent.tsx
Outdated
@@ -131,9 +132,9 @@ export class AlertModalContent extends RX.Component<AppModalContentProps, AppMod | |||
onPress={ e => this._onPressButton(btnSpec) } | |||
onHoverStart={ () => this.setState({ hoverIndex: i }) } | |||
onHoverEnd={ () => this.setState({ hoverIndex: -1 }) } | |||
style={ buttonStyle } | |||
style={ _.compact(buttonStyle) } |
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 are you compacting these styles? It's perfectly legit for style arrays to contain undefined values.
src/web/GestureView.tsx
Outdated
@@ -188,7 +188,7 @@ export class GestureView extends RX.ViewBase<Types.GestureViewProps, {}> { | |||
} | |||
|
|||
private _getPanPixelThreshold = () => { | |||
return this.props.panPixelThreshold > 0 ? this.props.panPixelThreshold : _panPixelThreshold; | |||
return (this.props.panPixelThreshold && this.props.panPixelThreshold > 0) ? this.props.panPixelThreshold : _panPixelThreshold; |
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.
Zero values work OK in this logic, but it would be better if the check for undefined was more explicit.
src/web/RootView.tsx
Outdated
@@ -462,9 +463,9 @@ export class RootView extends React.Component<RootViewProps, RootViewState> { | |||
private _startHidePopupTimer() { | |||
if (this.props.autoDismiss) { | |||
// Should we immediately hide it, or did the caller request a delay? | |||
if (this.props.autoDismissDelay > 0) { | |||
if (this.props.autoDismissDelay && this.props.autoDismissDelay > 0) { |
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.
Zero values work OK with this logic, but an explicit undefined type would be better.
src/web/Storage.ts
Outdated
@@ -14,7 +14,7 @@ import RX = require('../common/Interfaces'); | |||
export class Storage extends RX.Storage { | |||
getItem(key: string): SyncTasks.Promise<string|undefined> { | |||
const value = window.localStorage.getItem(key); | |||
return SyncTasks.Resolved<string|undefined>(value); | |||
return SyncTasks.Resolved<string|undefined>(value || undefined); |
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 do you want to turn empty strings into undefined here? I don't think that's the right semantic.
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.
Nothing seems out of place with respect to the TypeScript transformations. The interface changes seem alright, but you might want another opinion on that.
…m. Made the exported reactxp.ts files per-platform export types from the base classes instead of their specific implementation. This brought a bunch of interface holes to the surface.
…nitions (microsoft#280) * Rename microsoft#1 for ViewBase to fix caps * Rename microsoft#2 to fix ViewBase. Enabling forceConsistentCasingInFileNames. * Enabling noImplicitReturns, fixing a bug in native-common/Linking.ts * Enabling noImplicitThis * Enabling noUnusedLocals and fixing some bugs it found * Enabling strict null checks on reactxp * Addressing PR feedback * Fixing a bunch of type exporting/checking issues * Fixed a bunch of base interfaces and made everything inherit from them. Made the exported reactxp.ts files per-platform export types from the base classes instead of their specific implementation. This brought a bunch of interface holes to the surface.