From 5568ba87cc87b38a785b993963f22f877e1b0dcc Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Wed, 15 May 2024 20:03:56 +0200 Subject: [PATCH 1/5] Remove config --- packages/interactivity/tsconfig.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/interactivity/tsconfig.json b/packages/interactivity/tsconfig.json index 1d154e2089065d..6e33d8ff82d47e 100644 --- a/packages/interactivity/tsconfig.json +++ b/packages/interactivity/tsconfig.json @@ -3,9 +3,7 @@ "extends": "../../tsconfig.base.json", "compilerOptions": { "rootDir": "src", - "declarationDir": "build-types", - - "noImplicitAny": false + "declarationDir": "build-types" }, "include": [ "src/**/*" ] } From 5bb8ec92b7b4d044d86b9a584f49394876c1810c Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Wed, 15 May 2024 20:04:11 +0200 Subject: [PATCH 2/5] vdom --- packages/interactivity/src/vdom.ts | 45 +++++++++++++++++------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/packages/interactivity/src/vdom.ts b/packages/interactivity/src/vdom.ts index 98deca656cfa6c..be14723225c9ad 100644 --- a/packages/interactivity/src/vdom.ts +++ b/packages/interactivity/src/vdom.ts @@ -139,26 +139,31 @@ export function toVdom( root: Node ): Array< ComponentChild > { } if ( directives.length ) { - props.__directives = directives.reduce( - ( obj, [ name, ns, value ] ) => { - const directiveMatch = directiveParser.exec( name ); - if ( directiveMatch === null ) { - warn( `Found malformed directive name: ${ name }.` ); - return obj; - } - const prefix = directiveMatch[ 1 ] || ''; - const suffix = directiveMatch[ 2 ] || 'default'; - - obj[ prefix ] = obj[ prefix ] || []; - obj[ prefix ].push( { - namespace: ns ?? currentNamespace(), - value, - suffix, - } ); - return obj; - }, - {} - ); + const directivesProp: Record< + string, + Array< { + namespace: string | null; + value: unknown; + suffix: string; + } > + > = {}; + for ( const [ name, ns, value ] of directives ) { + const directiveMatch = directiveParser.exec( name ); + if ( directiveMatch === null ) { + warn( `Found malformed directive name: ${ name }.` ); + continue; + } + const prefix = directiveMatch[ 1 ] || ''; + const suffix = directiveMatch[ 2 ] || 'default'; + + directivesProp[ prefix ] = directivesProp[ prefix ] || []; + directivesProp[ prefix ].push( { + namespace: ns ?? currentNamespace(), + value, + suffix, + } ); + } + props.__directives = directivesProp; } // @ts-expect-error Fixed in upcoming preact release https://github.com/preactjs/preact/pull/4334 From 9d456c28f67ceb9416860fe423e036b374b5ea89 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Wed, 15 May 2024 20:06:14 +0200 Subject: [PATCH 3/5] No implicit any index --- packages/interactivity/src/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/interactivity/src/index.ts b/packages/interactivity/src/index.ts index 3c91e919d91bdc..87fa6dc7a939ec 100644 --- a/packages/interactivity/src/index.ts +++ b/packages/interactivity/src/index.ts @@ -32,7 +32,9 @@ export { useState, useRef } from 'preact/hooks'; const requiredConsent = 'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.'; -export const privateApis = ( lock ): any => { +export const privateApis = ( _lock: string ): any => { + // This is a public API - provide type input about the parameter but don't trust it. + const lock: unknown = _lock; if ( lock === requiredConsent ) { return { directivePrefix, From 9ffc28a65f82d77cdc0e4b62b997db9a47fe28bf Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Wed, 15 May 2024 20:13:57 +0200 Subject: [PATCH 4/5] I hate it (hooks) --- packages/interactivity/src/hooks.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/interactivity/src/hooks.tsx b/packages/interactivity/src/hooks.tsx index d8aa43d2c0e5af..33524cf37dc0c0 100644 --- a/packages/interactivity/src/hooks.tsx +++ b/packages/interactivity/src/hooks.tsx @@ -140,6 +140,7 @@ const namespaceStack: string[] = []; * @return The context content. */ export const getContext = < T extends object >( namespace?: string ): T => + // @ts-expect-error it's any! getScope()?.context[ namespace || getNamespace() ]; /** From 195e7e9c9c12645f28788c8d5dcadc46a1627c3f Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Thu, 13 Jun 2024 16:31:31 +0200 Subject: [PATCH 5/5] Add gutenberg-env types --- packages/interactivity/tsconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/interactivity/tsconfig.json b/packages/interactivity/tsconfig.json index 6e33d8ff82d47e..9e3edfe0ae443c 100644 --- a/packages/interactivity/tsconfig.json +++ b/packages/interactivity/tsconfig.json @@ -3,7 +3,8 @@ "extends": "../../tsconfig.base.json", "compilerOptions": { "rootDir": "src", - "declarationDir": "build-types" + "declarationDir": "build-types", + "types": [ "gutenberg-env" ] }, "include": [ "src/**/*" ] }