Skip to content

Commit fdccce2

Browse files
authored
Enabling TSC Safety Options (strict nulls, etc.) and Fixing Type Definitions (#280)
* Rename #1 for ViewBase to fix caps * Rename #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.
1 parent 51e95f1 commit fdccce2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1057
-935
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
"react-native-windows": "^0.33.0"
2626
},
2727
"devDependencies": {
28-
"typescript": "2.4.1",
29-
"tslint": "^5.0.0",
30-
"tslint-microsoft-contrib": "^5.0.1"
28+
"typescript": "2.6.0-dev.20170826",
29+
"tslint": "5.4.3",
30+
"tslint-microsoft-contrib": "5.0.0"
3131
},
3232
"homepage": "https://microsoft.github.io/reactxp/",
3333
"repository": {

src/android/Image.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
import RN = require('react-native');
1010

1111
import { Image as CommonImage } from '../native-common/Image';
12-
import Styles from '../native-common/Styles';
13-
import Types = require('../common/Types');
1412

1513
export class Image extends CommonImage {
1614
// Overwrite the style for android since native Image has a fade in animation when an image loads

src/android/ReactXP.ts

Lines changed: 92 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,43 @@
99
*/
1010

1111
import React = require('react');
12-
import RXInterface = require('../common/Interfaces');
13-
import RXTypes = require('../common/Types');
12+
1413
import AnimatedImpl = require('./Animated');
14+
import RXInterfaces = require('../common/Interfaces');
15+
import RXModuleInterface = require('../common/ModuleInterface');
16+
import RXTypes = require('../common/Types');
1517

1618
// -- STRANGE THINGS GOING ON HERE --
1719
// See web/ReactXP.tsx for more details.
1820

19-
import { default as AccessibilityImpl, Accessibility as AccessibilityType } from '../native-common/Accessibility';
20-
import { default as ActivityIndicatorImpl, ActivityIndicator as ActivityIndicatorType } from '../native-common/ActivityIndicator';
21-
import { default as AlertImpl, Alert as AlertType } from '../native-common/Alert';
22-
import { default as AppImpl, App as AppType } from '../native-common/App';
23-
import { default as ButtonImpl, Button as ButtonType } from '../native-common/Button';
24-
import { default as PickerImpl, Picker as PickerType } from '../native-common/Picker';
25-
import { default as ImageImpl, Image as ImageType } from './Image';
26-
import { default as ClipboardImpl, Clipboard as ClipboardType } from '../native-common/Clipboard';
27-
import { default as GestureViewImpl, GestureView as GestureViewType } from './GestureView';
28-
import { default as InputImpl, Input as InputType } from '../native-common/Input';
29-
import { default as InternationalImpl, International as InternationalType } from '../native-common/International';
30-
import { default as LinkImpl, Link as LinkType } from '../native-common/Link';
31-
import { default as LinkingImpl, Linking as LinkingType } from '../native-common/Linking';
32-
import { default as LocationImpl, Location as LocationType } from '../common/Location';
33-
import { default as ModalImpl, Modal as ModalType } from '../native-common/Modal';
34-
import { default as NetworkImpl, Network as NetworkType } from '../native-common/Network';
35-
import { default as PlatformImpl, Platform as PlatformType } from '../native-common/Platform';
36-
import { default as PopupImpl, Popup as PopupType } from '../native-common/Popup';
37-
import { default as ScrollViewImpl, ScrollView as ScrollViewType } from '../native-common/ScrollView';
38-
import { default as StatusBarImpl, StatusBar as StatusBarType } from './StatusBar';
39-
import { default as StorageImpl, Storage as StorageType } from '../native-common/Storage';
40-
import { default as StylesImpl, Styles as StylesType } from '../native-common/Styles';
41-
import { default as TextImpl, Text as TextType } from './Text';
42-
import { default as TextInputImpl, TextInput as TextInputType } from '../native-common/TextInput';
43-
import { default as UserInterfaceImpl, UserInterface as UserInterfaceType } from '../native-common/UserInterface';
44-
import { default as UserPresenceImpl, UserPresence as UserPresenceType } from '../native-common/UserPresence';
45-
import { default as ViewImpl, View as ViewType } from '../native-common/View';
46-
import { default as WebViewImpl, WebView as WebViewType } from '../native-common/WebView';
21+
import AccessibilityImpl from '../native-common/Accessibility';
22+
import ActivityIndicatorImpl from '../native-common/ActivityIndicator';
23+
import AlertImpl from '../native-common/Alert';
24+
import AppImpl from '../native-common/App';
25+
import ButtonImpl from '../native-common/Button';
26+
import PickerImpl from '../native-common/Picker';
27+
import ImageImpl from './Image';
28+
import ClipboardImpl from '../native-common/Clipboard';
29+
import GestureViewImpl from './GestureView';
30+
import InputImpl from '../native-common/Input';
31+
import InternationalImpl from '../native-common/International';
32+
import LinkImpl from '../native-common/Link';
33+
import LinkingImpl from '../native-common/Linking';
34+
import LocationImpl from '../common/Location';
35+
import ModalImpl from '../native-common/Modal';
36+
import NetworkImpl from '../native-common/Network';
37+
import PlatformImpl from '../native-common/Platform';
38+
import PopupImpl from '../native-common/Popup';
39+
import ScrollViewImpl from '../native-common/ScrollView';
40+
import StatusBarImpl from './StatusBar';
41+
import StorageImpl from '../native-common/Storage';
42+
import StylesImpl from '../native-common/Styles';
43+
import TextImpl from './Text';
44+
import TextInputImpl from '../native-common/TextInput';
45+
import UserInterfaceImpl from '../native-common/UserInterface';
46+
import UserPresenceImpl from '../native-common/UserPresence';
47+
import ViewImpl from '../native-common/View';
48+
import WebViewImpl from '../native-common/WebView';
4749
import ViewBase from '../native-common/ViewBase';
4850

4951
// Initialize the Android default view style. This is should not be required because RN for
@@ -66,64 +68,64 @@ AccessibilityUtil.setAccessibilityPlatformUtil(AccessibilityPlatformUtil);
6668
// See web/ReactXP.tsx for more details.
6769

6870
module ReactXP {
69-
export type Accessibility = AccessibilityType;
70-
export var Accessibility = AccessibilityImpl;
71-
export import Animated = AnimatedImpl.Animated;
72-
export type ActivityIndicator = ActivityIndicatorType;
73-
export var ActivityIndicator = ActivityIndicatorImpl;
74-
export type Alert = AlertType;
75-
export var Alert = AlertImpl;
76-
export type App = AppType;
77-
export var App = AppImpl;
78-
export type Button = ButtonType;
79-
export var Button = ButtonImpl;
80-
export type Picker = PickerType;
81-
export var Picker = PickerImpl;
82-
export type Clipboard = ClipboardType;
83-
export var Clipboard = ClipboardImpl;
84-
export type GestureView = GestureViewType;
85-
export var GestureView = GestureViewImpl;
86-
export type Image = ImageType;
87-
export var Image = ImageImpl;
88-
export type Input = InputType;
89-
export var Input = InputImpl;
90-
export type International = InternationalType;
91-
export var International = InternationalImpl;
92-
export type Link = LinkType;
93-
export var Link = LinkImpl;
94-
export type Linking = LinkingType;
95-
export var Linking = LinkingImpl;
96-
export type Location = LocationType;
97-
export var Location = LocationImpl;
98-
export type Modal = ModalType;
99-
export var Modal = ModalImpl;
100-
export type Network = NetworkType;
101-
export var Network = NetworkImpl;
102-
export type Platform = PlatformType;
103-
export var Platform = PlatformImpl;
104-
export type Popup = PopupType;
105-
export var Popup = PopupImpl;
106-
export type ScrollView = ScrollViewType;
107-
export var ScrollView = ScrollViewImpl;
108-
export type StatusBar = StatusBarType;
109-
export var StatusBar = StatusBarImpl;
110-
export type Storage = StorageType;
111-
export var Storage = StorageImpl;
112-
export type Styles = StylesType;
113-
export var Styles = StylesImpl;
114-
export type Text = TextType;
115-
export var Text = TextImpl;
116-
export type TextInput = TextInputType;
117-
export var TextInput = TextInputImpl;
118-
export type UserInterface = UserInterfaceType;
119-
export var UserInterface = UserInterfaceImpl;
120-
export type UserPresence = UserPresenceType;
121-
export var UserPresence = UserPresenceImpl;
122-
export type View = ViewType;
123-
export var View = ViewImpl;
124-
export type WebView = WebViewType;
125-
export var WebView = WebViewImpl;
71+
export type Accessibility = RXInterfaces.Accessibility;
72+
export var Accessibility: RXInterfaces.Accessibility = AccessibilityImpl;
73+
export type ActivityIndicator = RXInterfaces.ActivityIndicator;
74+
export var ActivityIndicator: typeof RXInterfaces.ActivityIndicator = ActivityIndicatorImpl;
75+
export type Alert = RXInterfaces.Alert;
76+
export var Alert: RXInterfaces.Alert = AlertImpl;
77+
export type App = RXInterfaces.App;
78+
export var App: RXInterfaces.App = AppImpl;
79+
export type Button = RXInterfaces.Button;
80+
export var Button: typeof RXInterfaces.Button = ButtonImpl;
81+
export type Picker = RXInterfaces.Picker;
82+
export var Picker: typeof RXInterfaces.Picker = PickerImpl;
83+
export type Clipboard = RXInterfaces.Clipboard;
84+
export var Clipboard: RXInterfaces.Clipboard = ClipboardImpl;
85+
export type GestureView = RXInterfaces.GestureView;
86+
export var GestureView: typeof RXInterfaces.GestureView = GestureViewImpl;
87+
export type Image = RXInterfaces.Image;
88+
export var Image: RXInterfaces.ImageConstructor = ImageImpl;
89+
export type Input = RXInterfaces.Input;
90+
export var Input: RXInterfaces.Input = InputImpl;
91+
export type International = RXInterfaces.International;
92+
export var International: RXInterfaces.International = InternationalImpl;
93+
export type Link = RXInterfaces.Link;
94+
export var Link: typeof RXInterfaces.Link = LinkImpl;
95+
export type Linking = RXInterfaces.Linking;
96+
export var Linking: RXInterfaces.Linking = LinkingImpl;
97+
export type Location = RXInterfaces.Location;
98+
export var Location: RXInterfaces.Location = LocationImpl;
99+
export type Modal = RXInterfaces.Modal;
100+
export var Modal: RXInterfaces.Modal = ModalImpl;
101+
export type Network = RXInterfaces.Network;
102+
export var Network: RXInterfaces.Network = NetworkImpl;
103+
export type Platform = RXInterfaces.Platform;
104+
export var Platform: RXInterfaces.Platform = PlatformImpl;
105+
export type Popup = RXInterfaces.Popup;
106+
export var Popup: RXInterfaces.Popup = PopupImpl;
107+
export type ScrollView = RXInterfaces.ScrollView;
108+
export var ScrollView: RXInterfaces.ScrollViewConstructor = ScrollViewImpl;
109+
export type StatusBar = RXInterfaces.StatusBar;
110+
export var StatusBar: RXInterfaces.StatusBar = StatusBarImpl;
111+
export type Storage = RXInterfaces.Storage;
112+
export var Storage: RXInterfaces.Storage = StorageImpl;
113+
export type Styles = RXInterfaces.Styles;
114+
export var Styles: RXInterfaces.Styles = StylesImpl;
115+
export type Text = RXInterfaces.Text;
116+
export var Text: typeof RXInterfaces.Text = TextImpl;
117+
export type TextInput = RXInterfaces.TextInput;
118+
export var TextInput: typeof RXInterfaces.TextInput = TextInputImpl;
119+
export type UserInterface = RXInterfaces.UserInterface;
120+
export var UserInterface: RXInterfaces.UserInterface = UserInterfaceImpl;
121+
export type UserPresence = RXInterfaces.UserPresence;
122+
export var UserPresence: RXInterfaces.UserPresence = UserPresenceImpl;
123+
export type View = RXInterfaces.View;
124+
export var View: typeof RXInterfaces.View = ViewImpl;
125+
export type WebView = RXInterfaces.WebView;
126+
export var WebView: RXInterfaces.WebViewConstructor = WebViewImpl;
126127

128+
export import Animated = AnimatedImpl;
127129
export import CommonProps = RXTypes.CommonProps;
128130
export import CommonStyledProps = RXTypes.CommonStyledProps;
129131
export import Types = RXTypes;
@@ -134,14 +136,12 @@ module ReactXP {
134136
export var __spread = (React as any).__spread;
135137
}
136138

137-
export = ReactXP;
138-
139139
// -- STRANGE THINGS GOING ON HERE --
140140
// See web/ReactXP.tsx for more details.
141141

142-
/* tslint:disable:no-unused-variable */
143-
var _rxImplementsRxInterface: RXInterface.ReactXP = ReactXP;
144-
/* tslint:enable:no-unused-variable */
142+
var _rxImplementsRxInterface: typeof RXModuleInterface.ReactXP = ReactXP;
143+
_rxImplementsRxInterface = _rxImplementsRxInterface;
144+
export = ReactXP;
145145

146146
/*
147147
var rx = module.exports;

src/android/Text.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ var _styles = {
2323
};
2424

2525
export class Text extends CommonText {
26-
protected _getStyles(): Types.TextStyleRuleSet | Types.TextStyleRuleSet[] {
27-
return Styles.combine<Types.TextStyle>([_styles.defaultText, this.props.style]);
26+
protected _getStyles(): Types.StyleRuleSetRecursiveArray<Types.TextStyleRuleSet> {
27+
return [_styles.defaultText, this.props.style];
2828
}
2929

3030
// We override the render method to work around a couple of Android-specific
@@ -38,7 +38,7 @@ export class Text extends CommonText {
3838
style={ this._getStyles() }
3939
ref='nativeText'
4040
importantForAccessibility={ importantForAccessibility }
41-
numberOfLines={ this.props.numberOfLines === 0 ? null : this.props.numberOfLines }
41+
numberOfLines={ this.props.numberOfLines === 0 ? undefined : this.props.numberOfLines }
4242
allowFontScaling={ this.props.allowFontScaling }
4343
maxContentSizeMultiplier={ this.props.maxContentSizeMultiplier }
4444
ellipsizeMode={ this.props.ellipsizeMode }

src/common/Accessibility.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import RX = require('../common/Interfaces');
1414
export abstract class Accessibility extends RX.Accessibility {
1515
abstract isScreenReaderEnabled(): boolean;
1616

17+
screenReaderChangedEvent = new SubscribableEvent<(isEnabled: boolean) => void>();
18+
1719
newAnnouncementReadyEvent = new SubscribableEvent<(announcement: string) => void>();
1820
announceForAccessibility(announcement: string): void {
1921
this.newAnnouncementReadyEvent.fire(announcement);

src/common/AccessibilityUtil.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@ export abstract class AccessibilityPlatformUtil {
2424
}
2525

2626
export abstract class AccessibilityUtil {
27-
isHidden(importantForAccessibility: Types.ImportantForAccessibility): boolean {
27+
isHidden(importantForAccessibility: Types.ImportantForAccessibility|undefined): boolean {
2828
if (importantForAccessibility) {
2929
const importantForAccessibilityString = this.importantForAccessibilityToString(importantForAccessibility);
3030
return importantForAccessibilityString === ImportantForAccessibilityMap[Types.ImportantForAccessibility.NoHideDescendants];
3131
}
32-
return undefined;
32+
return false;
3333
}
3434

35-
importantForAccessibilityToString(importantForAccessibility: Types.ImportantForAccessibility,
36-
defaultImportantForAccessibility?: Types.ImportantForAccessibility): string {
35+
importantForAccessibilityToString(importantForAccessibility: Types.ImportantForAccessibility|undefined,
36+
defaultImportantForAccessibility?: Types.ImportantForAccessibility): string|undefined {
3737
importantForAccessibility = importantForAccessibility || defaultImportantForAccessibility;
3838

39-
if (ImportantForAccessibilityMap[importantForAccessibility]) {
39+
if (importantForAccessibility && ImportantForAccessibilityMap[importantForAccessibility]) {
4040
return ImportantForAccessibilityMap[importantForAccessibility];
4141
}
4242
return undefined;
4343
}
4444

45-
protected abstract accessibilityLiveRegionToString(liveRegion: Types.AccessibilityLiveRegion): string;
45+
protected abstract accessibilityLiveRegionToString(liveRegion: Types.AccessibilityLiveRegion): string|undefined;
4646
protected abstract accessibilityTraitToString(trait: Types.AccessibilityTrait | Types.AccessibilityTrait[],
47-
defaultTrait?: Types.AccessibilityTrait): string | string[];
47+
defaultTrait?: Types.AccessibilityTrait): string | string[] | undefined;
4848
}

0 commit comments

Comments
 (0)