Skip to content

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

Merged
merged 9 commits into from
Sep 19, 2017

Conversation

deregtd
Copy link
Collaborator

@deregtd deregtd commented Sep 18, 2017

  •    "noImplicitReturns": true,
    
  •    "noImplicitThis": true,
    
  •    "noUnusedLocals": true,
    
  •    "strictNullChecks": true,
    
  •    "forceConsistentCasingInFileNames": true,
    

@msftclas
Copy link

@deregtd,
Thanks for your contribution as a Microsoft full-time employee or intern. You do not need to sign a CLA.
Thanks,
Microsoft Pull Request Bot

type: React.ComponentClass<P>;
props: P;
}
// interface Element<P> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not remove?

Copy link
Collaborator Author

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.

@@ -7,7 +7,7 @@
* MacOS implementation of Input interface.
*/

import RN = require('react-native');
//import RN = require('react-native');
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not remove?

Copy link
Collaborator Author

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.

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]);
Copy link
Contributor

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.

@@ -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;
Copy link
Contributor

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;
Copy link
Contributor

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

talked offline

type: React.ComponentClass<P>;
props: P;
}
// interface Element<P> {
Copy link
Contributor

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.

@@ -1115,6 +1115,10 @@ export type Dimensions = {
width: number;
height: number;
};
export type OptionalDimensions = {
Copy link
Contributor

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.


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);
Copy link
Contributor

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.

@@ -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) }
Copy link
Contributor

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.

@@ -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;
Copy link
Contributor

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.

@@ -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) {
Copy link
Contributor

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.

@@ -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);
Copy link
Contributor

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.

Copy link
Contributor

@ms-markda ms-markda left a 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.

David de Regt added 2 commits September 18, 2017 16:54
…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.
@deregtd deregtd merged commit fdccce2 into master Sep 19, 2017
@deregtd deregtd deleted the dadere/TSOptions branch September 19, 2017 04:47
berickson1 pushed a commit to berickson1/reactxp that referenced this pull request Oct 22, 2018
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants