From 2d59d2ffa861b15d52a3ccc934870fd27a4611bf Mon Sep 17 00:00:00 2001 From: luhc228 Date: Wed, 21 Sep 2022 16:01:14 +0800 Subject: [PATCH 1/2] feat: enhance inner types --- examples/app-config/src/typings.d.ts | 15 +- examples/app-config/tsconfig.json | 2 +- examples/basic-project/src/pages/about.tsx | 3 +- examples/basic-project/src/typings.d.ts | 15 +- examples/basic-project/tsconfig.json | 2 +- examples/csr-project/src/typings.d.ts | 15 +- examples/csr-project/tsconfig.json | 2 +- examples/rax-inline-style/src/typings.d.ts | 15 +- examples/rax-inline-style/tsconfig.json | 2 +- examples/rax-project/src/typings.d.ts | 15 +- examples/rax-project/tsconfig.json | 2 +- examples/with-antd-mobile/src/typings.d.ts | 5 +- examples/with-antd-mobile/tsconfig.json | 2 +- examples/with-antd/src/typings.d.ts | 15 +- examples/with-antd/tsconfig.json | 2 +- examples/with-fusion/src/typings.d.ts | 15 +- examples/with-fusion/tsconfig.json | 2 +- examples/with-pha/src/typings.d.ts | 15 +- examples/with-pha/tsconfig.json | 2 +- examples/with-plugin-request/src/typings.d.ts | 15 +- examples/with-plugin-request/tsconfig.json | 2 +- packages/ice/package.json | 3 +- packages/ice/types.d.ts | 150 ++++++++++++++++++ 23 files changed, 173 insertions(+), 143 deletions(-) create mode 100644 packages/ice/types.d.ts diff --git a/examples/app-config/src/typings.d.ts b/examples/app-config/src/typings.d.ts index b2780a236..1f6ba4ffa 100644 --- a/examples/app-config/src/typings.d.ts +++ b/examples/app-config/src/typings.d.ts @@ -1,14 +1 @@ -declare module '*.module.less' { - const classes: { [key: string]: string }; - export default classes; -} - -declare module '*.module.css' { - const classes: { [key: string]: string }; - export default classes; -} - -declare module '*.module.scss' { - const classes: { [key: string]: string }; - export default classes; -} +/// diff --git a/examples/app-config/tsconfig.json b/examples/app-config/tsconfig.json index 7f2f2ffce..26fd9ec79 100644 --- a/examples/app-config/tsconfig.json +++ b/examples/app-config/tsconfig.json @@ -28,5 +28,5 @@ } }, "include": ["src", ".ice", "ice.config.*"], - "exclude": ["node_modules", "build", "public"] + "exclude": ["build", "public"] } \ No newline at end of file diff --git a/examples/basic-project/src/pages/about.tsx b/examples/basic-project/src/pages/about.tsx index dce5b82a5..36c837861 100644 --- a/examples/basic-project/src/pages/about.tsx +++ b/examples/basic-project/src/pages/about.tsx @@ -1,6 +1,5 @@ import { Link, useData, useConfig, history } from 'ice'; import { isWeb } from '@uni/env'; -// @ts-expect-error import url from './ice.png'; interface Data { @@ -8,7 +7,7 @@ interface Data { } export default function About() { - const data = useData(); + const data = useData() as Data; const config = useConfig(); console.log('render About', 'data', data, 'config', config); diff --git a/examples/basic-project/src/typings.d.ts b/examples/basic-project/src/typings.d.ts index b2780a236..1f6ba4ffa 100644 --- a/examples/basic-project/src/typings.d.ts +++ b/examples/basic-project/src/typings.d.ts @@ -1,14 +1 @@ -declare module '*.module.less' { - const classes: { [key: string]: string }; - export default classes; -} - -declare module '*.module.css' { - const classes: { [key: string]: string }; - export default classes; -} - -declare module '*.module.scss' { - const classes: { [key: string]: string }; - export default classes; -} +/// diff --git a/examples/basic-project/tsconfig.json b/examples/basic-project/tsconfig.json index 7f2f2ffce..26fd9ec79 100644 --- a/examples/basic-project/tsconfig.json +++ b/examples/basic-project/tsconfig.json @@ -28,5 +28,5 @@ } }, "include": ["src", ".ice", "ice.config.*"], - "exclude": ["node_modules", "build", "public"] + "exclude": ["build", "public"] } \ No newline at end of file diff --git a/examples/csr-project/src/typings.d.ts b/examples/csr-project/src/typings.d.ts index b2780a236..1f6ba4ffa 100644 --- a/examples/csr-project/src/typings.d.ts +++ b/examples/csr-project/src/typings.d.ts @@ -1,14 +1 @@ -declare module '*.module.less' { - const classes: { [key: string]: string }; - export default classes; -} - -declare module '*.module.css' { - const classes: { [key: string]: string }; - export default classes; -} - -declare module '*.module.scss' { - const classes: { [key: string]: string }; - export default classes; -} +/// diff --git a/examples/csr-project/tsconfig.json b/examples/csr-project/tsconfig.json index 7f2f2ffce..26fd9ec79 100644 --- a/examples/csr-project/tsconfig.json +++ b/examples/csr-project/tsconfig.json @@ -28,5 +28,5 @@ } }, "include": ["src", ".ice", "ice.config.*"], - "exclude": ["node_modules", "build", "public"] + "exclude": ["build", "public"] } \ No newline at end of file diff --git a/examples/rax-inline-style/src/typings.d.ts b/examples/rax-inline-style/src/typings.d.ts index b2780a236..1f6ba4ffa 100644 --- a/examples/rax-inline-style/src/typings.d.ts +++ b/examples/rax-inline-style/src/typings.d.ts @@ -1,14 +1 @@ -declare module '*.module.less' { - const classes: { [key: string]: string }; - export default classes; -} - -declare module '*.module.css' { - const classes: { [key: string]: string }; - export default classes; -} - -declare module '*.module.scss' { - const classes: { [key: string]: string }; - export default classes; -} +/// diff --git a/examples/rax-inline-style/tsconfig.json b/examples/rax-inline-style/tsconfig.json index 7f2f2ffce..26fd9ec79 100644 --- a/examples/rax-inline-style/tsconfig.json +++ b/examples/rax-inline-style/tsconfig.json @@ -28,5 +28,5 @@ } }, "include": ["src", ".ice", "ice.config.*"], - "exclude": ["node_modules", "build", "public"] + "exclude": ["build", "public"] } \ No newline at end of file diff --git a/examples/rax-project/src/typings.d.ts b/examples/rax-project/src/typings.d.ts index b2780a236..1f6ba4ffa 100644 --- a/examples/rax-project/src/typings.d.ts +++ b/examples/rax-project/src/typings.d.ts @@ -1,14 +1 @@ -declare module '*.module.less' { - const classes: { [key: string]: string }; - export default classes; -} - -declare module '*.module.css' { - const classes: { [key: string]: string }; - export default classes; -} - -declare module '*.module.scss' { - const classes: { [key: string]: string }; - export default classes; -} +/// diff --git a/examples/rax-project/tsconfig.json b/examples/rax-project/tsconfig.json index 7f2f2ffce..26fd9ec79 100644 --- a/examples/rax-project/tsconfig.json +++ b/examples/rax-project/tsconfig.json @@ -28,5 +28,5 @@ } }, "include": ["src", ".ice", "ice.config.*"], - "exclude": ["node_modules", "build", "public"] + "exclude": ["build", "public"] } \ No newline at end of file diff --git a/examples/with-antd-mobile/src/typings.d.ts b/examples/with-antd-mobile/src/typings.d.ts index 1336d3bde..1f6ba4ffa 100644 --- a/examples/with-antd-mobile/src/typings.d.ts +++ b/examples/with-antd-mobile/src/typings.d.ts @@ -1,4 +1 @@ -declare module '*.module.css' { - const classes: { [key: string]: string }; - export default classes; -} \ No newline at end of file +/// diff --git a/examples/with-antd-mobile/tsconfig.json b/examples/with-antd-mobile/tsconfig.json index 0413c5297..212e8bb11 100644 --- a/examples/with-antd-mobile/tsconfig.json +++ b/examples/with-antd-mobile/tsconfig.json @@ -28,5 +28,5 @@ } }, "include": ["src", ".ice", "ice.config.*"], - "exclude": ["node_modules", "build", "public"] + "exclude": ["build", "public"] } diff --git a/examples/with-antd/src/typings.d.ts b/examples/with-antd/src/typings.d.ts index b2780a236..1f6ba4ffa 100644 --- a/examples/with-antd/src/typings.d.ts +++ b/examples/with-antd/src/typings.d.ts @@ -1,14 +1 @@ -declare module '*.module.less' { - const classes: { [key: string]: string }; - export default classes; -} - -declare module '*.module.css' { - const classes: { [key: string]: string }; - export default classes; -} - -declare module '*.module.scss' { - const classes: { [key: string]: string }; - export default classes; -} +/// diff --git a/examples/with-antd/tsconfig.json b/examples/with-antd/tsconfig.json index 7f2f2ffce..26fd9ec79 100644 --- a/examples/with-antd/tsconfig.json +++ b/examples/with-antd/tsconfig.json @@ -28,5 +28,5 @@ } }, "include": ["src", ".ice", "ice.config.*"], - "exclude": ["node_modules", "build", "public"] + "exclude": ["build", "public"] } \ No newline at end of file diff --git a/examples/with-fusion/src/typings.d.ts b/examples/with-fusion/src/typings.d.ts index b2780a236..1f6ba4ffa 100644 --- a/examples/with-fusion/src/typings.d.ts +++ b/examples/with-fusion/src/typings.d.ts @@ -1,14 +1 @@ -declare module '*.module.less' { - const classes: { [key: string]: string }; - export default classes; -} - -declare module '*.module.css' { - const classes: { [key: string]: string }; - export default classes; -} - -declare module '*.module.scss' { - const classes: { [key: string]: string }; - export default classes; -} +/// diff --git a/examples/with-fusion/tsconfig.json b/examples/with-fusion/tsconfig.json index 7f2f2ffce..26fd9ec79 100644 --- a/examples/with-fusion/tsconfig.json +++ b/examples/with-fusion/tsconfig.json @@ -28,5 +28,5 @@ } }, "include": ["src", ".ice", "ice.config.*"], - "exclude": ["node_modules", "build", "public"] + "exclude": ["build", "public"] } \ No newline at end of file diff --git a/examples/with-pha/src/typings.d.ts b/examples/with-pha/src/typings.d.ts index b2780a236..1f6ba4ffa 100644 --- a/examples/with-pha/src/typings.d.ts +++ b/examples/with-pha/src/typings.d.ts @@ -1,14 +1 @@ -declare module '*.module.less' { - const classes: { [key: string]: string }; - export default classes; -} - -declare module '*.module.css' { - const classes: { [key: string]: string }; - export default classes; -} - -declare module '*.module.scss' { - const classes: { [key: string]: string }; - export default classes; -} +/// diff --git a/examples/with-pha/tsconfig.json b/examples/with-pha/tsconfig.json index 7f2f2ffce..26fd9ec79 100644 --- a/examples/with-pha/tsconfig.json +++ b/examples/with-pha/tsconfig.json @@ -28,5 +28,5 @@ } }, "include": ["src", ".ice", "ice.config.*"], - "exclude": ["node_modules", "build", "public"] + "exclude": ["build", "public"] } \ No newline at end of file diff --git a/examples/with-plugin-request/src/typings.d.ts b/examples/with-plugin-request/src/typings.d.ts index b2780a236..1f6ba4ffa 100644 --- a/examples/with-plugin-request/src/typings.d.ts +++ b/examples/with-plugin-request/src/typings.d.ts @@ -1,14 +1 @@ -declare module '*.module.less' { - const classes: { [key: string]: string }; - export default classes; -} - -declare module '*.module.css' { - const classes: { [key: string]: string }; - export default classes; -} - -declare module '*.module.scss' { - const classes: { [key: string]: string }; - export default classes; -} +/// diff --git a/examples/with-plugin-request/tsconfig.json b/examples/with-plugin-request/tsconfig.json index 7f2f2ffce..26fd9ec79 100644 --- a/examples/with-plugin-request/tsconfig.json +++ b/examples/with-plugin-request/tsconfig.json @@ -28,5 +28,5 @@ } }, "include": ["src", ".ice", "ice.config.*"], - "exclude": ["node_modules", "build", "public"] + "exclude": ["build", "public"] } \ No newline at end of file diff --git a/packages/ice/package.json b/packages/ice/package.json index f03fc95a3..ea06b35b3 100644 --- a/packages/ice/package.json +++ b/packages/ice/package.json @@ -13,7 +13,8 @@ "esm", "!esm/**/*.map", "templates", - "openChrome.applescript" + "openChrome.applescript", + "types.d.ts" ], "engines": { "node": ">=14.19.0", diff --git a/packages/ice/types.d.ts b/packages/ice/types.d.ts new file mode 100644 index 000000000..d1f814ed4 --- /dev/null +++ b/packages/ice/types.d.ts @@ -0,0 +1,150 @@ +// CSS modules +declare module '*.module.less' { + const classes: { [key: string]: string }; + export default classes; +} + +declare module '*.module.css' { + const classes: { [key: string]: string }; + export default classes; +} + +declare module '*.module.scss' { + const classes: { [key: string]: string }; + export default classes; +} + +// images +declare module '*.jpg' { + const src: string; + export default src; +} +declare module '*.jpeg' { + const src: string; + export default src; +} +declare module '*.png' { + const src: string; + export default src; +} +declare module '*.gif' { + const src: string; + export default src; +} +declare module '*.svg' { + const src: string; + export default src; +} +declare module '*.ico' { + const src: string; + export default src; +} +declare module '*.webp' { + const src: string; + export default src; +} +declare module '*.avif' { + const src: string; + export default src; +} + +// media +declare module '*.mp4' { + const src: string; + export default src; +} +declare module '*.webm' { + const src: string; + export default src; +} +declare module '*.ogg' { + const src: string; + export default src; +} +declare module '*.mp3' { + const src: string; + export default src; +} +declare module '*.wav' { + const src: string; + export default src; +} +declare module '*.flac' { + const src: string; + export default src; +} +declare module '*.aac' { + const src: string; + export default src; +} + +// fonts +declare module '*.woff' { + const src: string; + export default src; +} +declare module '*.woff2' { + const src: string; + export default src; +} +declare module '*.eot' { + const src: string; + export default src; +} +declare module '*.ttf' { + const src: string; + export default src; +} +declare module '*.otf' { + const src: string; + export default src; +} + +// web worker +declare module '*?worker' { + const workerConstructor: { + new(): Worker; + }; + export default workerConstructor; +} +declare module '*?worker&inline' { + const workerConstructor: { + new(): Worker; + }; + export default workerConstructor; +} +declare module '*?sharedworker' { + const sharedWorkerConstructor: { + new(): SharedWorker; + }; + export default sharedWorkerConstructor; +} + +// other +declare module '*.pdf' { + const src: string; + export default src; +} +declare module '*.txt' { + const src: string; + export default src; +} +declare module '*?url' { + const src: string; + export default src; +} +declare module '*?raw' { + const src: string; + export default src; +} + +declare namespace NodeJS { + export interface ProcessEnv { + ICE_CORE_NODE_ENV: 'development' | 'production'; + ICE_CORE_MODE: string; + ICE_CORE_ROUTER: 'true' | 'false'; + ICE_CORE_ERROR_BOUNDARY: 'true' | 'false'; + ICE_CORE_INITIAL_DATA: 'true' | 'false'; + ICE_CORE_DEV_PORT: number; + } +} From 4a9dedbbcc69add7de3b19d5628d1529e52a06a7 Mon Sep 17 00:00:00 2001 From: luhc228 Date: Wed, 21 Sep 2022 16:06:45 +0800 Subject: [PATCH 2/2] chore: revert type --- examples/basic-project/src/pages/about.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/basic-project/src/pages/about.tsx b/examples/basic-project/src/pages/about.tsx index 36c837861..935e30549 100644 --- a/examples/basic-project/src/pages/about.tsx +++ b/examples/basic-project/src/pages/about.tsx @@ -7,7 +7,7 @@ interface Data { } export default function About() { - const data = useData() as Data; + const data = useData(); const config = useConfig(); console.log('render About', 'data', data, 'config', config);