From 465a80df763c7486b46cd4f9da9ca144d8c09473 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Tue, 15 Dec 2020 22:59:30 -0500 Subject: [PATCH 1/7] [ts] Use CSSStyleDeclaration for CSS property list This removes the validation we added in 10.5.6, since it's unfortunately not yet possible to allow known CSS properties and wildcard `--.*` custom properties (see attempt: https://gist.github.com/developit/3a29186588634648e45e8afb199626df). --- src/jsx.d.ts | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/jsx.d.ts b/src/jsx.d.ts index bf51c02762d..5d989f7c65d 100644 --- a/src/jsx.d.ts +++ b/src/jsx.d.ts @@ -1,6 +1,5 @@ // Users who only use Preact for SSR might not specify "dom" in their lib in tsconfig.json /// -import * as CSS from './jsx-csstype'; type Defaultize = // Distribute over unions @@ -33,18 +32,11 @@ export namespace JSXInternal { children: any; } - interface CSSProperties< - TLength = (string & {}) | number, - TTime = string & {} - > extends CSS.Properties { - /** - * The index signature was removed to enable closed typing for style - * using CSSType. You're able to use type assertion or module augmentation - * to add properties or an index signature of your own. - * - * For examples and more information, visit: - * https://github.com/frenic/csstype#what-should-i-do-when-i-get-type-errors - */ + type DOMCSSProperties = { + [key in keyof CSSStyleDeclaration]?: CSSStyleDeclaration[key] extends string ? (CSSStyleDeclaration[key] | number | null | undefined) : never; + }; + interface CSSProperties extends DOMCSSProperties { + [key: string]: string | number | null | undefined; } interface SVGAttributes From 3c9d4996035f54d50342dedc93e9811b03766b9c Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Tue, 15 Dec 2020 23:00:16 -0500 Subject: [PATCH 2/7] Delete copy-csstype.js --- config/copy-csstype.js | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 config/copy-csstype.js diff --git a/config/copy-csstype.js b/config/copy-csstype.js deleted file mode 100644 index 423628c4e04..00000000000 --- a/config/copy-csstype.js +++ /dev/null @@ -1,6 +0,0 @@ -const fs = require('fs'); -const path = require('path'); - -const src = path.join(__dirname, '..', 'node_modules', 'csstype', 'index.d.ts'); -const dest = path.join(__dirname, '..', 'src', 'jsx-csstype.d.ts'); -fs.copyFileSync(src, dest); From 6818c7d11f586d54129365dddefd4f1e5d631d3a Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Tue, 15 Dec 2020 23:00:57 -0500 Subject: [PATCH 3/7] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fa18296f8ff..c63819621a6 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ "build:test-utils": "microbundle build --raw --cwd test-utils", "build:compat": "microbundle build --raw --cwd compat --globals 'preact/hooks=preactHooks'", "build:jsx": "microbundle build --raw --cwd jsx-runtime", - "postbuild": "node ./config/node-13-exports.js && node ./config/copy-csstype.js", + "postbuild": "node ./config/node-13-exports.js", "dev": "microbundle watch --raw --format cjs", "dev:hooks": "microbundle watch --raw --format cjs --cwd hooks", "dev:compat": "microbundle watch --raw --format cjs --cwd compat --globals 'preact/hooks=preactHooks'", From 739a78b409eb90d57875edfacf18a65243db5f51 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Wed, 16 Dec 2020 21:01:07 -0500 Subject: [PATCH 4/7] update package lock --- package-lock.json | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/package-lock.json b/package-lock.json index a08669d16a8..5759068871f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2552,6 +2552,16 @@ "dev": true, "optional": true }, + "bindings": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", + "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", + "dev": true, + "optional": true, + "requires": { + "file-uri-to-path": "1.0.0" + } + }, "blob": { "version": "0.0.5", "resolved": "https://registry.npmjs.org/blob/-/blob-0.0.5.tgz", @@ -5982,6 +5992,13 @@ "integrity": "sha512-qyQ0pzAy78gVoJsmYeNgl8uH8yKhr1lVhW7JbzJmnlRi0I4R2eEDEJZVKG8agpDnLpacwNbDhLNG/LMdxHD2YQ==", "dev": true }, + "file-uri-to-path": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", + "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", + "dev": true, + "optional": true + }, "filename-regex": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/filename-regex/-/filename-regex-2.0.1.tgz", @@ -17155,6 +17172,7 @@ "dev": true, "optional": true, "requires": { + "bindings": "^1.5.0", "nan": "^2.12.1" } }, From c66454a3e003c9c0d0d02f5029fd50d5b234977c Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Wed, 16 Dec 2020 21:06:38 -0500 Subject: [PATCH 5/7] fix CSS number properties --- src/jsx.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/jsx.d.ts b/src/jsx.d.ts index 5d989f7c65d..dd7d73cfc8b 100644 --- a/src/jsx.d.ts +++ b/src/jsx.d.ts @@ -33,7 +33,9 @@ export namespace JSXInternal { } type DOMCSSProperties = { - [key in keyof CSSStyleDeclaration]?: CSSStyleDeclaration[key] extends string ? (CSSStyleDeclaration[key] | number | null | undefined) : never; + [key in keyof CSSStyleDeclaration]?: CSSStyleDeclaration[key] extends string + ? string | number | null | undefined + : never; }; interface CSSProperties extends DOMCSSProperties { [key: string]: string | number | null | undefined; From 687d280eba555236a026d5dd70afd6b0c71463f1 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Wed, 16 Dec 2020 21:54:53 -0500 Subject: [PATCH 6/7] maybe changing the order will work --- src/jsx.d.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/jsx.d.ts b/src/jsx.d.ts index dd7d73cfc8b..87f30a5946b 100644 --- a/src/jsx.d.ts +++ b/src/jsx.d.ts @@ -37,9 +37,10 @@ export namespace JSXInternal { ? string | number | null | undefined : never; }; - interface CSSProperties extends DOMCSSProperties { + type AllCSSProperties = { [key: string]: string | number | null | undefined; - } + }; + interface CSSProperties extends AllCSSProperties, DOMCSSProperties {} interface SVGAttributes extends HTMLAttributes { From 0244869d467684ca1bae432d3b01e3d8012d9617 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Mon, 21 Dec 2020 11:46:21 -0500 Subject: [PATCH 7/7] Fix for TS<=3.6 --- src/jsx.d.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/jsx.d.ts b/src/jsx.d.ts index 87f30a5946b..3fb5ed8828e 100644 --- a/src/jsx.d.ts +++ b/src/jsx.d.ts @@ -33,14 +33,21 @@ export namespace JSXInternal { } type DOMCSSProperties = { - [key in keyof CSSStyleDeclaration]?: CSSStyleDeclaration[key] extends string - ? string | number | null | undefined - : never; + [key in keyof Omit< + CSSStyleDeclaration, + | 'item' + | 'setProperty' + | 'removeProperty' + | 'getPropertyValue' + | 'getPropertyPriority' + >]?: string | number | null | undefined; }; type AllCSSProperties = { [key: string]: string | number | null | undefined; }; - interface CSSProperties extends AllCSSProperties, DOMCSSProperties {} + interface CSSProperties extends AllCSSProperties, DOMCSSProperties { + cssText?: string | null; + } interface SVGAttributes extends HTMLAttributes {