|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Greg Price < [email protected]> |
| 3 | +Date: Tue, 7 Jun 2022 20:57:09 -0700 |
| 4 | +Subject: [tsflower] Replace interface-extends with spread for non-interface |
| 5 | + bases |
| 6 | +MIME-Version: 1.0 |
| 7 | +Content-Type: text/plain; charset=UTF-8 |
| 8 | +Content-Transfer-Encoding: 8bit |
| 9 | + |
| 10 | +In TypeScript, `interface T { … }` and `type T = { … }`, when there |
| 11 | +are no other type definitions for T, mean exactly the same thing. |
| 12 | + |
| 13 | +In Flow, they're different -- an interface is a different kind of |
| 14 | +type from an object type. In particular, a further interface |
| 15 | +definition can extend an interface, but can't extend an object type. |
| 16 | + |
| 17 | +Currently, TsFlower emits an interface when it sees an interface. |
| 18 | +That's good if the type definitions are going to go on to use that |
| 19 | +interface as the base for another interface, or for a class; it's |
| 20 | +bad if it was extending another type that turns out to be just an |
| 21 | +object type. |
| 22 | + |
| 23 | +Probably an improvement to the heuristic would be to convert an |
| 24 | +interface declaration to an object type, with `extends` turned into |
| 25 | +a spread, when the base is an object type -- as it is in these |
| 26 | +examples. |
| 27 | +--- |
| 28 | + .../lib/typescript/SafeArea.types.js.flow | 22 +++++++++++-------- |
| 29 | + .../lib/typescript/SafeAreaContext.js.flow | 12 +++++----- |
| 30 | + .../specs/NativeSafeAreaProvider.js.flow | 8 ++++--- |
| 31 | + .../specs/NativeSafeAreaView.js.flow | 10 +++++---- |
| 32 | + 4 files changed, 31 insertions(+), 21 deletions(-) |
| 33 | + |
| 34 | +diff --git types/react-native-safe-area-context/lib/typescript/SafeArea.types.js.flow types/react-native-safe-area-context/lib/typescript/SafeArea.types.js.flow |
| 35 | +index 88ba6cc09..056367669 100644 |
| 36 | +--- types/react-native-safe-area-context/lib/typescript/SafeArea.types.js.flow |
| 37 | ++++ types/react-native-safe-area-context/lib/typescript/SafeArea.types.js.flow |
| 38 | +@@ -33,13 +33,17 @@ export interface Metrics { |
| 39 | + export type InsetChangedEvent = $tsflower_subst$RN$NativeSyntheticEvent<Metrics>; |
| 40 | + export type InsetChangeNativeCallback = (event: InsetChangedEvent) => void; |
| 41 | + |
| 42 | +-export interface NativeSafeAreaProviderProps extends $tsflower_subst$RN$ViewProps { |
| 43 | +- children?: $tsflower_subst$React$ReactNode; |
| 44 | +- onInsetsChange: InsetChangeNativeCallback; |
| 45 | +-} |
| 46 | ++export type NativeSafeAreaProviderProps = { |
| 47 | ++ ...$tsflower_subst$RN$ViewProps, |
| 48 | ++ children?: $tsflower_subst$React$ReactNode, |
| 49 | ++ onInsetsChange: InsetChangeNativeCallback, |
| 50 | ++ ... |
| 51 | ++}; |
| 52 | + |
| 53 | +-export interface NativeSafeAreaViewProps extends $tsflower_subst$RN$ViewProps { |
| 54 | +- children?: $tsflower_subst$React$ReactNode; |
| 55 | +- mode?: 'padding' | 'margin'; |
| 56 | +- edges?: $ReadOnlyArray<Edge>; |
| 57 | +-} |
| 58 | ++export type NativeSafeAreaViewProps = { |
| 59 | ++ ...$tsflower_subst$RN$ViewProps, |
| 60 | ++ children?: $tsflower_subst$React$ReactNode, |
| 61 | ++ mode?: 'padding' | 'margin', |
| 62 | ++ edges?: $ReadOnlyArray<Edge>, |
| 63 | ++ ... |
| 64 | ++}; |
| 65 | +diff --git types/react-native-safe-area-context/lib/typescript/SafeAreaContext.js.flow types/react-native-safe-area-context/lib/typescript/SafeAreaContext.js.flow |
| 66 | +index 7231a733b..5e7699444 100644 |
| 67 | +--- types/react-native-safe-area-context/lib/typescript/SafeAreaContext.js.flow |
| 68 | ++++ types/react-native-safe-area-context/lib/typescript/SafeAreaContext.js.flow |
| 69 | +@@ -18,11 +18,13 @@ import { type EdgeInsets, type Metrics, type Rect } from './SafeArea.types'; |
| 70 | + declare export var SafeAreaInsetsContext: $tsflower_subst$React$Context<EdgeInsets | null>; |
| 71 | + declare export var SafeAreaFrameContext: $tsflower_subst$React$Context<Rect | null>; |
| 72 | + |
| 73 | +-export interface SafeAreaProviderProps extends $tsflower_subst$RN$ViewProps { |
| 74 | +- children?: $tsflower_subst$React$ReactNode; |
| 75 | +- initialMetrics?: Metrics | null; |
| 76 | +- initialSafeAreaInsets?: EdgeInsets | null; |
| 77 | +-} |
| 78 | ++export type SafeAreaProviderProps = { |
| 79 | ++ ...$tsflower_subst$RN$ViewProps, |
| 80 | ++ children?: $tsflower_subst$React$ReactNode, |
| 81 | ++ initialMetrics?: Metrics | null, |
| 82 | ++ initialSafeAreaInsets?: EdgeInsets | null, |
| 83 | ++ ... |
| 84 | ++}; |
| 85 | + |
| 86 | + declare export function SafeAreaProvider(SafeAreaProviderProps): $tsflower_subst$React$JSX$Element; |
| 87 | + declare export function useSafeAreaInsets(): EdgeInsets; |
| 88 | +diff --git types/react-native-safe-area-context/lib/typescript/specs/NativeSafeAreaProvider.js.flow types/react-native-safe-area-context/lib/typescript/specs/NativeSafeAreaProvider.js.flow |
| 89 | +index 7a1594b3b..5d9e21df4 100644 |
| 90 | +--- types/react-native-safe-area-context/lib/typescript/specs/NativeSafeAreaProvider.js.flow |
| 91 | ++++ types/react-native-safe-area-context/lib/typescript/specs/NativeSafeAreaProvider.js.flow |
| 92 | +@@ -27,8 +27,10 @@ export type Event = Readonly<{ |
| 93 | + ... |
| 94 | + }>; |
| 95 | + |
| 96 | +-export interface NativeProps extends $tsflower_subst$RN$ViewProps { |
| 97 | +- onInsetsChange?: DirectEventHandler<Event, 'paperInsetsChange'>; |
| 98 | +-} |
| 99 | ++export type NativeProps = { |
| 100 | ++ ...$tsflower_subst$RN$ViewProps, |
| 101 | ++ onInsetsChange?: DirectEventHandler<Event, 'paperInsetsChange'>, |
| 102 | ++ ... |
| 103 | ++}; |
| 104 | + declare var _default: HostComponent<NativeProps>; |
| 105 | + export default _default; |
| 106 | +diff --git types/react-native-safe-area-context/lib/typescript/specs/NativeSafeAreaView.js.flow types/react-native-safe-area-context/lib/typescript/specs/NativeSafeAreaView.js.flow |
| 107 | +index 6e8337b9b..300c246bb 100644 |
| 108 | +--- types/react-native-safe-area-context/lib/typescript/specs/NativeSafeAreaView.js.flow |
| 109 | ++++ types/react-native-safe-area-context/lib/typescript/specs/NativeSafeAreaView.js.flow |
| 110 | +@@ -5,10 +5,12 @@ import type { ViewProps as $tsflower_subst$RN$ViewProps } from 'tsflower/subst/r |
| 111 | + import { typeof WithDefault } from 'react-native/Libraries/Types/CodegenTypes'; |
| 112 | + import { type HostComponent } from 'react-native'; |
| 113 | + |
| 114 | +-export interface NativeProps extends $tsflower_subst$RN$ViewProps { |
| 115 | +- mode?: WithDefault<'padding' | 'margin', 'padding'>; |
| 116 | +- edges /* tsflower-warning: unimplemented: 'readonly' as type operator */?: string[] /* readonly string[] */; |
| 117 | +-} |
| 118 | ++export type NativeProps = { |
| 119 | ++ ...$tsflower_subst$RN$ViewProps, |
| 120 | ++ mode?: WithDefault<'padding' | 'margin', 'padding'>, |
| 121 | ++ edges /* tsflower-warning: unimplemented: 'readonly' as type operator */?: string[] /* readonly string[] */, |
| 122 | ++ ... |
| 123 | ++}; |
| 124 | + |
| 125 | + declare var _default: HostComponent<NativeProps>; |
| 126 | + export default _default; |
| 127 | +-- |
| 128 | +2.32.0 |
| 129 | + |
0 commit comments