From 6f5ada87485b754cda3a5e93675237a131250f9e Mon Sep 17 00:00:00 2001 From: Chi-Hsuan Huang Date: Thu, 14 Apr 2022 09:44:34 +0800 Subject: [PATCH] Add Typescript type declarations for js packages --- packages/js/data/package.json | 1 + packages/js/data/src/index.ts | 8 +++++++- packages/js/data/tsconfig.json | 7 +++++-- packages/js/experimental/package.json | 1 + packages/js/experimental/tsconfig.json | 7 +++++-- packages/js/explat/package.json | 1 + packages/js/explat/tsconfig.json | 7 +++++-- packages/js/navigation/package.json | 1 + packages/js/navigation/tsconfig.json | 7 +++++-- packages/js/onboarding/package.json | 1 + packages/js/onboarding/tsconfig.json | 7 +++++-- 11 files changed, 37 insertions(+), 11 deletions(-) diff --git a/packages/js/data/package.json b/packages/js/data/package.json index deb941ac2e7..079c9978580 100644 --- a/packages/js/data/package.json +++ b/packages/js/data/package.json @@ -19,6 +19,7 @@ }, "main": "build/index.js", "module": "build-module/index.js", + "types": "build-types", "react-native": "src/index", "dependencies": { "@woocommerce/date": "workspace:*", diff --git a/packages/js/data/src/index.ts b/packages/js/data/src/index.ts index 469218ce89f..acda849d359 100644 --- a/packages/js/data/src/index.ts +++ b/packages/js/data/src/index.ts @@ -17,7 +17,9 @@ import type { NOTES_STORE_NAME } from './notes'; import type { REPORTS_STORE_NAME } from './reports'; import type { ITEMS_STORE_NAME } from './items'; import type { COUNTRIES_STORE_NAME } from './countries'; +import type { PAYMENT_GATEWAYS_STORE_NAME } from './payment-gateways'; import { OnboardingSelectors } from './onboarding/selectors'; + import { WPDataSelectors } from './types'; import { PluginSelectors } from './plugins/selectors'; @@ -63,6 +65,7 @@ export { NAVIGATION_STORE_NAME } from './navigation'; export { withNavigationHydration } from './navigation/with-navigation-hydration'; export { PAYMENT_GATEWAYS_STORE_NAME } from './payment-gateways'; +import { PaymentSelectors } from './payment-gateways/selectors'; export { getFilterQuery, @@ -102,7 +105,8 @@ export type WCDataStoreName = | typeof NOTES_STORE_NAME | typeof REPORTS_STORE_NAME | typeof ITEMS_STORE_NAME - | typeof COUNTRIES_STORE_NAME; + | typeof COUNTRIES_STORE_NAME + | typeof PAYMENT_GATEWAYS_STORE_NAME; // As we add types to all the package selectors we can fill out these unknown types with real ones. See one // of the already typed selectors for an example of how you can do this. @@ -114,6 +118,8 @@ export type WCSelectorType< T > = T extends typeof REVIEWS_STORE_NAME ? PluginSelectors : T extends typeof ONBOARDING_STORE_NAME ? OnboardingSelectors + : T extends typeof PAYMENT_GATEWAYS_STORE_NAME + ? PaymentSelectors : T extends typeof USER_STORE_NAME ? WPDataSelectors : T extends typeof OPTIONS_STORE_NAME diff --git a/packages/js/data/tsconfig.json b/packages/js/data/tsconfig.json index e8f14a25fa4..ea9f201d401 100644 --- a/packages/js/data/tsconfig.json +++ b/packages/js/data/tsconfig.json @@ -2,6 +2,9 @@ "extends": "../tsconfig", "compilerOptions": { "rootDir": "src", - "outDir": "build-module" + "outDir": "build-module", + "declaration": true, + "declarationMap": true, + "declarationDir": "./build-types" } -} \ No newline at end of file +} diff --git a/packages/js/experimental/package.json b/packages/js/experimental/package.json index e78452c4d6a..66bd374e07f 100644 --- a/packages/js/experimental/package.json +++ b/packages/js/experimental/package.json @@ -19,6 +19,7 @@ }, "main": "build/index.js", "module": "build-module/index.js", + "types": "build-types", "react-native": "src/index", "sideEffects": [ "build-style/**", diff --git a/packages/js/experimental/tsconfig.json b/packages/js/experimental/tsconfig.json index 5ca11d01623..b2ffc578087 100644 --- a/packages/js/experimental/tsconfig.json +++ b/packages/js/experimental/tsconfig.json @@ -3,6 +3,9 @@ "compilerOptions": { "rootDir": "src", "outDir": "build-module", - "target": "es2019" + "target": "es2019", + "declaration": true, + "declarationMap": true, + "declarationDir": "./build-types" } -} \ No newline at end of file +} diff --git a/packages/js/explat/package.json b/packages/js/explat/package.json index f6c3d728f8e..2bbd9aea625 100644 --- a/packages/js/explat/package.json +++ b/packages/js/explat/package.json @@ -20,6 +20,7 @@ }, "main": "build/index.js", "module": "build-module/index.js", + "types": "build-types", "react-native": "src/index", "publishConfig": { "access": "public" diff --git a/packages/js/explat/tsconfig.json b/packages/js/explat/tsconfig.json index 75ce1c823b6..a63e196f6fd 100644 --- a/packages/js/explat/tsconfig.json +++ b/packages/js/explat/tsconfig.json @@ -2,6 +2,9 @@ "extends": "../tsconfig", "compilerOptions": { "rootDir": "src", - "outDir": "build-module" + "outDir": "build-module", + "declaration": true, + "declarationMap": true, + "declarationDir": "./build-types" }, -} \ No newline at end of file +} diff --git a/packages/js/navigation/package.json b/packages/js/navigation/package.json index 6c4e5f064c8..b61d3793a94 100644 --- a/packages/js/navigation/package.json +++ b/packages/js/navigation/package.json @@ -19,6 +19,7 @@ }, "main": "build/index.js", "module": "build-module/index.js", + "types": "build-types", "react-native": "src/index", "dependencies": { "@wordpress/api-fetch": "^6.0.1", diff --git a/packages/js/navigation/tsconfig.json b/packages/js/navigation/tsconfig.json index e8f14a25fa4..ea9f201d401 100644 --- a/packages/js/navigation/tsconfig.json +++ b/packages/js/navigation/tsconfig.json @@ -2,6 +2,9 @@ "extends": "../tsconfig", "compilerOptions": { "rootDir": "src", - "outDir": "build-module" + "outDir": "build-module", + "declaration": true, + "declarationMap": true, + "declarationDir": "./build-types" } -} \ No newline at end of file +} diff --git a/packages/js/onboarding/package.json b/packages/js/onboarding/package.json index 07bfb1e640d..10c26033dd6 100644 --- a/packages/js/onboarding/package.json +++ b/packages/js/onboarding/package.json @@ -19,6 +19,7 @@ }, "main": "build/index.js", "module": "build-module/index.js", + "types": "build-types", "react-native": "src/index", "publishConfig": { "access": "public" diff --git a/packages/js/onboarding/tsconfig.json b/packages/js/onboarding/tsconfig.json index e8f14a25fa4..ea9f201d401 100644 --- a/packages/js/onboarding/tsconfig.json +++ b/packages/js/onboarding/tsconfig.json @@ -2,6 +2,9 @@ "extends": "../tsconfig", "compilerOptions": { "rootDir": "src", - "outDir": "build-module" + "outDir": "build-module", + "declaration": true, + "declarationMap": true, + "declarationDir": "./build-types" } -} \ No newline at end of file +}