Skip to content

Commit a885dfd

Browse files
authored
declare other global typings (#2678)
* declare other global typings * Cleanup old typings * Create common typings and fix import paths * Remove old typings folder * Remove measureme typings * Move fsTagName global interface to recorderType file
1 parent 64964aa commit a885dfd

37 files changed

+47
-659
lines changed

src/commons/asBaseComponent.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as Modifiers from './modifiers';
44
import {Scheme, SchemeChangeListener, ThemeManager} from '../style';
55
import forwardRef from './forwardRef';
66
import UIComponent from './UIComponent';
7+
import type {ThemeComponent} from '../typings/common';
78

89
export interface BaseComponentInjectedProps {
910
/**
@@ -41,7 +42,7 @@ function asBaseComponent<PROPS, STATICS = {}>(WrappedComponent: React.ComponentT
4142
Scheme.removeChangeListener(this.appearanceListener);
4243
}
4344

44-
appearanceListener: SchemeChangeListener = (colorScheme) => {
45+
appearanceListener: SchemeChangeListener = colorScheme => {
4546
// iOS 13 and above will trigger this call with the wrong colorScheme value. So just ignore returned colorScheme for now
4647
// https://github.com/facebook/react-native/issues/28525
4748
// this.setState({colorScheme: Appearance.getColorScheme()});

src/commons/modifiers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {BorderRadiusesLiterals} from '../style/borderRadiuses';
55
import TypographyPresets from '../style/typographyPresets';
66
import {SpacingLiterals} from '../style/spacings';
77
import {colorsPalette} from '../style/colorsPalette';
8+
import type {Dictionary} from '../typings/common';
9+
810
export const FLEX_KEY_PATTERN = /^flex(G|S)?(-\d*)?$/;
911
export const PADDING_KEY_PATTERN = new RegExp(`padding[LTRBHV]?-([0-9]*|${Spacings.getKeysPattern()})`);
1012
export const MARGIN_KEY_PATTERN = new RegExp(`margin[LTRBHV]?-([0-9]*|${Spacings.getKeysPattern()})`);

src/components/button/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import {Platform, StyleSheet, LayoutAnimation, LayoutChangeEvent, ImageStyle, Te
44
import {asBaseComponent, forwardRef, Constants} from '../../commons/new';
55
import {Colors, Typography, BorderRadiuses} from 'style';
66
import TouchableOpacity from '../touchableOpacity';
7+
import type {Dictionary} from '../../typings/common';
78
import Text from '../text';
89
import Image from '../image';
910
import Icon from '../icon';
10-
1111
import {
1212
ButtonSize,
1313
ButtonAnimationDirection,
@@ -17,9 +17,10 @@ import {
1717
DEFAULT_PROPS,
1818
ButtonSizeProp
1919
} from './ButtonTypes';
20+
import {PADDINGS, HORIZONTAL_PADDINGS, MIN_WIDTH, DEFAULT_SIZE} from './ButtonConstants';
21+
2022
export {ButtonSize, ButtonAnimationDirection, ButtonProps};
2123

22-
import {PADDINGS, HORIZONTAL_PADDINGS, MIN_WIDTH, DEFAULT_SIZE} from './ButtonConstants';
2324

2425
class Button extends PureComponent<Props, ButtonState> {
2526
static displayName = 'Button';

src/components/icon/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, {useMemo, forwardRef} from 'react';
33
import {Image, ImageProps, StyleSheet} from 'react-native';
44
import {asBaseComponent, BaseComponentInjectedProps, MarginModifiers, Constants} from '../../commons/new';
55
import {getAsset, isSvg, isBase64ImageContent} from '../../utils/imageUtils';
6-
import {RecorderProps} from '../../../typings/recorderTypes';
6+
import {RecorderProps} from '../../typings/recorderTypes';
77
import SvgImage from '../svgImage';
88

99
export type IconProps = Omit<ImageProps, 'source'> &

src/components/image/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
BaseComponentInjectedProps,
1919
MarginModifiers
2020
} from '../../commons/new';
21-
import {RecorderProps} from '../../../typings/recorderTypes';
21+
import {RecorderProps} from '../../typings/recorderTypes';
2222
import {getAsset, isSvg} from '../../utils/imageUtils';
2323
import Overlay, {OverlayTypeType, OverlayIntensityType} from '../overlay';
2424
import SvgImage from '../svgImage';

src/components/picker/types.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {ModalTopBarProps} from '../modal/TopBar';
55
// TODO: Replace with new TextField Props after migration to new TextField has completed
66
// import {TextFieldProps} from '../../../typings/components/Inputs';
77
import {TextFieldMethods, TextFieldProps as NewTextFieldProps} from '../../incubator/TextField';
8+
import type {ThemeComponent} from '../../typings/common';
89

910
// Note: enum values are uppercase due to legacy
1011
export enum PickerModes {

src/components/sortableList/SortableListContext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {createContext} from 'react';
22
import {ViewProps} from 'react-native';
33
import {SharedValue} from 'react-native-reanimated';
4+
import type {Dictionary} from '../../typings/common';
45
import {Data, SortableListItemProps} from './types';
56

67
export interface SortableListContextType<ItemT extends SortableListItemProps> {

src/components/sortableList/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import SortableListContext from './SortableListContext';
88
import SortableListItem, {DEFAULT_LIST_ITEM_HEIGHT} from './SortableListItem';
99
import {useDidUpdate, useThemeProps} from 'hooks';
1010
import {SortableListProps, SortableListItemProps} from './types';
11+
import type {Dictionary} from '../../typings/common';
12+
1113
export {SortableListProps, SortableListItemProps};
1214

1315
function generateItemsOrder<ItemT extends SortableListItemProps>(data: SortableListProps<ItemT>['data']) {

src/components/tabController/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import TabBarItem, {TabControllerItemProps} from './TabBarItem';
1010
import TabPage from './TabPage';
1111
import PageCarousel from './PageCarousel';
1212
import useImperativeTabControllerHandle, {TabControllerImperativeMethods} from './useImperativeTabControllerHandle';
13+
import type {ThemeComponent} from '../../typings/common';
14+
1315
export {TabControllerItemProps, TabControllerImperativeMethods};
1416

1517
interface TabControllerStatics {

src/components/text/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
FlexModifiers,
1313
Constants
1414
} from '../../commons/new';
15-
import {RecorderProps} from '../../../typings/recorderTypes';
15+
import {RecorderProps} from '../../typings/recorderTypes';
1616
import {Colors} from 'style';
1717
import {TextUtils} from 'utils';
1818

src/components/textField/TextFieldMigrator.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import hoistStatics from 'hoist-non-react-statics';
44
import OldTextField from './index';
55
import NewTextField, {TextFieldStaticMembers, TextFieldProps} from '../../incubator/TextField';
66
import {LogService} from '../../services';
7+
import type {Dictionary} from '../../typings/common';
78

89
export interface TextFieldMigratorComponent
910
extends React.ForwardRefExoticComponent<TextFieldProps>,

src/components/touchableOpacity/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
ForwardRefInjectedProps,
1313
ContainerModifiers
1414
} from '../../commons/new';
15-
import {RecorderProps} from '../../../typings/recorderTypes';
15+
import {RecorderProps} from '../../typings/recorderTypes';
1616
import IncubatorTouchableOpacity from '../../incubator/TouchableOpacity';
1717
import {ViewProps} from '../view';
1818

src/components/view/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import {useModifiers, useThemeProps} from 'hooks';
22
import React, {useEffect, useMemo, useState} from 'react';
33
import {View as RNView, SafeAreaView, Animated, ViewProps as RNViewProps, StyleProp, ViewStyle} from 'react-native';
44
import {Constants, ContainerModifiers} from '../../commons/new';
5-
import {RecorderProps} from '../../../typings/recorderTypes';
5+
import type {ThemeComponent} from '../../typings/common';
6+
import type {RecorderProps} from '../../typings/recorderTypes';
67

78
export interface ViewProps extends Omit<RNViewProps, 'style'>, ThemeComponent, ContainerModifiers, RecorderProps {
89
/**

src/incubator/TextField/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
ForwardRefInjectedProps
1010
} from '../../commons/new';
1111
import {TextProps} from '../../components/text';
12-
import {RecorderProps} from '../../../typings/recorderTypes';
12+
import {RecorderProps} from '../../typings/recorderTypes';
1313
import {PropsWithChildren, ReactElement} from 'react';
1414
import {ViewProps} from '../../components/view';
1515

src/index.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export {
126126
export {default as ProgressBar, ProgressBarProps} from './components/progressBar';
127127
export {default as RadioButton, RadioButtonProps} from './components/radioButton';
128128
export {default as RadioGroup, RadioGroupProps} from './components/radioGroup';
129-
export type {RecorderProps} from '../typings/recorderTypes';
129+
export type {RecorderProps} from './typings/recorderTypes';
130130
export {default as ScrollBar, ScrollBarProps} from './components/scrollBar';
131131
export {default as SectionsWheelPicker, SectionsWheelPickerProps} from './components/sectionsWheelPicker';
132132
export {
@@ -189,14 +189,3 @@ export {
189189
// export {default as TextFieldTestKit} from './incubator/TextField/TextField.driver';
190190

191191
// export {default as ButtonDriverFactory} from './components/button/Button.driver';
192-
//================ Manual typings (all those exports should be removed one day) ==========
193-
// export {
194-
// // BaseInput,
195-
// // TextArea,
196-
// // TextField,
197-
// // MaskedInput,
198-
// // SharedTransition,
199-
// // Toast,
200-
// // BaseComponent,
201-
// // PureBaseComponent
202-
// } from '../typings';

src/style/borderRadiuses.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import _ from 'lodash';
22
import Constants from '../commons/Constants';
3+
import type {Dictionary, ExtendTypeWith} from '../typings/common';
34

45
// TODO: enable template type after we're ready to use TS 4.4.0
56
// interface IBorderRadiusesLiterals {
67
// [key: `br${number}`]: number
78
// }
89

9-
export const BorderRadiusesLiterals/* : IBorderRadiusesLiterals */ = {
10+
export const BorderRadiusesLiterals /* : IBorderRadiusesLiterals */ = {
1011
br0: Constants.isIOS ? 0 : 0,
1112
br10: Constants.isIOS ? 3 : 2,
1213
br20: 6,
@@ -18,7 +19,7 @@ export const BorderRadiusesLiterals/* : IBorderRadiusesLiterals */ = {
1819
};
1920

2021
export class BorderRadiuses {
21-
loadBorders(borders: Dictionary<number>/* IBorderRadiusesLiterals */) {
22+
loadBorders(borders: Dictionary<number> /* IBorderRadiusesLiterals */) {
2223
_.forEach(borders, (value, key) => {
2324
//@ts-ignore
2425
this[key] = value;

src/style/colors.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import DesignTokensDM from './designTokensDM';
99
//@ts-ignore
1010
import ColorName from './colorName';
1111
import Scheme, {Schemes, SchemeType} from './scheme';
12+
import type {ExtendTypeWith} from '../typings/common';
1213

1314
export type DesignToken = {semantic?: [string]; resource_paths?: [string]; toString: Function};
1415
export type TokensOptions = {primaryColor: string};

src/style/shadows.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {ShadowStyleIOS} from 'react-native';
22
import _ from 'lodash';
33
import Colors from './colors';
4+
import type {Dictionary} from '../typings/common';
45

56
type Shadow = {top?: ShadowStyleIOS; bottom?: ShadowStyleIOS} & ShadowStyleIOS;
67

src/style/spacings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import _ from 'lodash';
2+
import type {Dictionary, ExtendTypeWith} from '../typings/common';
23

34
export const SpacingLiterals = {
45
s1: 4,

src/style/themeManager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import _ from 'lodash';
22
import type {Context} from 'react';
3+
import type {Dictionary, Extendable} from '../typings/common';
34

45
interface Theme {
56
components: Extendable;

src/style/typography.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import _ from 'lodash';
33
import Constants from '../commons/Constants';
44

55
import TypographyPresets from './typographyPresets';
6+
import type {Dictionary, ExtendTypeWith} from '../typings/common';
67

78
type MeasureTextTypography = TextStyle & {allowFontScaling?: boolean};
89

src/typings/common.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export interface Extendable {
2+
[key: string]: any;
3+
}
4+
5+
export type Constructor<T, TA = any> = new (...args: TA[]) => T;
6+
export type ExtendTypeWith<T extends Constructor<any>, OtherObject extends object> = Constructor<
7+
InstanceType<T> & OtherObject,
8+
ConstructorParameters<T>
9+
>;
10+
export type Dictionary<TYPE> = {[key: string]: TYPE};
11+
12+
export interface ThemeComponent {
13+
useCustomTheme?: boolean;
14+
}

typings/global.d.ts renamed to src/typings/module.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ declare namespace globalThis {
33
var _UILIB_TESTING: boolean;
44
}
55

6+
// This support importing png files, typing wise
7+
declare module '*.png';
8+
69
declare namespace JSX {
710
interface IntrinsicAttributes {
811
fsTagName?: string;
File renamed without changes.

typings/commons/index.d.ts

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)