diff --git a/Libraries/ReactNative/AppRegistry.d.ts b/Libraries/ReactNative/AppRegistry.d.ts index d6fa9627581a9a..2e792e79b24021 100644 --- a/Libraries/ReactNative/AppRegistry.d.ts +++ b/Libraries/ReactNative/AppRegistry.d.ts @@ -30,7 +30,9 @@ export type ComponentProviderInstrumentationHook = ( scopedPerformanceLogger: IPerformanceLogger, ) => React.ComponentType; -export type WrapperComponentProvider = (any) => React.ComponentType; +export type WrapperComponentProvider = ( + appParameters: any, +) => React.ComponentType; /** * `AppRegistry` is the JS entry point to running all React Native apps. App @@ -50,7 +52,7 @@ export type WrapperComponentProvider = (any) => React.ComponentType; export namespace AppRegistry { export function setWrapperComponentProvider( provider: WrapperComponentProvider, - ); + ): void; export function registerConfig(config: AppConfig[]): void; @@ -94,7 +96,7 @@ export namespace AppRegistry { export function setComponentProviderInstrumentationHook( hook: ComponentProviderInstrumentationHook, - ); + ): void; export function registerHeadlessTask( taskKey: string, diff --git a/Libraries/ReactNative/AppRegistry.js b/Libraries/ReactNative/AppRegistry.js index 486cf541184c29..d38745e54bf09f 100644 --- a/Libraries/ReactNative/AppRegistry.js +++ b/Libraries/ReactNative/AppRegistry.js @@ -51,7 +51,9 @@ export type Registry = { runnables: Runnables, ... }; -export type WrapperComponentProvider = any => React$ComponentType; +export type WrapperComponentProvider = ( + appParameters: any, +) => React$ComponentType; const runnables: Runnables = {}; let runCount = 1; diff --git a/Libraries/StyleSheet/StyleSheet.d.ts b/Libraries/StyleSheet/StyleSheet.d.ts index b3325098207274..53ab3e1f2784ff 100644 --- a/Libraries/StyleSheet/StyleSheet.d.ts +++ b/Libraries/StyleSheet/StyleSheet.d.ts @@ -87,10 +87,14 @@ export namespace StyleSheet { * an array, saving allocations and maintaining reference equality for * PureComponent checks. */ - export function compose( - style1: StyleProp | Array>, - style2: StyleProp | Array>, - ): StyleProp; + export function compose< + T extends ViewStyle | TextStyle | ImageStyle, + U extends T, + V extends T, + >( + style1: StyleProp | Array>, + style2: StyleProp | Array>, + ): StyleProp; /** * WARNING: EXPERIMENTAL. Breaking changes will probably happen a lot and will diff --git a/package.json b/package.json index 1b203687fe5b55..82aacc1ccc4bf2 100644 --- a/package.json +++ b/package.json @@ -97,7 +97,8 @@ "test-e2e-local": "node ./scripts/test-e2e-local.js", "test-e2e-local-clean": "node ./scripts/test-e2e-local-clean.js", "test-ios": "./scripts/objc-test.sh test", - "test-typescript": "dtslint types" + "test-typescript": "dtslint types", + "test-typescript-offline": "dtslint --localTs node_modules/typescript/lib types" }, "workspaces": [ "packages/*", diff --git a/scripts/run-ci-javascript-tests.js b/scripts/run-ci-javascript-tests.js index bdb9fedd7c7e77..30fee2573f955a 100644 --- a/scripts/run-ci-javascript-tests.js +++ b/scripts/run-ci-javascript-tests.js @@ -65,6 +65,13 @@ try { throw Error(exitCode); } + describe('Test: TypeScript tests'); + if (exec(`${YARN_BINARY} run test-typescript-offline`).code) { + echo('Failed to run TypeScript tests.'); + exitCode = 1; + throw Error(exitCode); + } + exitCode = 0; } finally { // Do cleanup here diff --git a/types/__typetests__/index.tsx b/types/__typetests__/index.tsx index 5e95a30edc5c10..070a59abe2cc45 100644 --- a/types/__typetests__/index.tsx +++ b/types/__typetests__/index.tsx @@ -290,24 +290,49 @@ const combinedStyle6: StyleProp = StyleSheet.compose( null, ); -// The following use of the compose method is invalid: -// @ts-expect-error -const combinedStyle7 = StyleSheet.compose(composeImageStyle, composeTextStyle); +const page = StyleSheet.create({ + container: { + flex: 1, + padding: 24, + backgroundColor: '#fff', + }, + text: { + fontSize: 30, + color: '#000', + }, +}); -// @ts-expect-error +const lists = StyleSheet.create({ + listContainer: { + flex: 1, + backgroundColor: '#61dafb', + }, + listItem: { + fontStyle: 'italic', + fontWeight: 'bold', + }, +}); + +const container = StyleSheet.compose(page.container, lists.listContainer); +; +const text = StyleSheet.compose(page.text, lists.listItem); +; + +// The following use of the compose method is invalid: const combinedStyle8: StyleProp = StyleSheet.compose( + // @ts-expect-error composeTextStyle, composeTextStyle, ); -// @ts-expect-error const combinedStyle9: StyleProp = StyleSheet.compose( + // @ts-expect-error [composeTextStyle], null, ); -// @ts-expect-error const combinedStyle10: StyleProp = StyleSheet.compose( + // @ts-expect-error Math.random() < 0.5 ? composeTextStyle : null, null, );