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() ]; /** 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, 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 diff --git a/packages/interactivity/tsconfig.json b/packages/interactivity/tsconfig.json index 1d154e2089065d..9e3edfe0ae443c 100644 --- a/packages/interactivity/tsconfig.json +++ b/packages/interactivity/tsconfig.json @@ -4,8 +4,7 @@ "compilerOptions": { "rootDir": "src", "declarationDir": "build-types", - - "noImplicitAny": false + "types": [ "gutenberg-env" ] }, "include": [ "src/**/*" ] }