Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactivity API: No implicit any #61695

Draft
wants to merge 5 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/interactivity/src/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
* @return The context content.
*/
export const getContext = < T extends object >( namespace?: string ): T =>
// @ts-expect-error it's any!
getScope()?.context[ namespace || getNamespace() ];

/**
Expand Down Expand Up @@ -281,7 +282,7 @@
}
const current = {
...resolvedStore,
context: getScope().context[ namespace ],

Check failure on line 285 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 6

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.

Check failure on line 285 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 7

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.

Check failure on line 285 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 8

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.

Check failure on line 285 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Build JavaScript assets for PHP unit tests

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.

Check failure on line 285 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 5

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.

Check failure on line 285 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 2

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.

Check failure on line 285 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 4

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.

Check failure on line 285 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 1

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.

Check failure on line 285 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 3

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.

Check failure on line 285 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Build Release Artifact

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.

Check failure on line 285 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Run performance tests

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.

Check failure on line 285 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / All

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
};
try {
// TODO: Support lazy/dynamically initialized stores
Expand Down Expand Up @@ -326,7 +327,7 @@
};

// Component that wraps each priority level of directives of an element.
const Directives = ( {

Check failure on line 330 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 6

'Directives' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.

Check failure on line 330 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 7

'Directives' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.

Check failure on line 330 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 8

'Directives' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.

Check failure on line 330 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Build JavaScript assets for PHP unit tests

'Directives' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.

Check failure on line 330 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 5

'Directives' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.

Check failure on line 330 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 2

'Directives' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.

Check failure on line 330 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 4

'Directives' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.

Check failure on line 330 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 1

'Directives' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.

Check failure on line 330 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 3

'Directives' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.

Check failure on line 330 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Build Release Artifact

'Directives' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.

Check failure on line 330 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Run performance tests

'Directives' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.

Check failure on line 330 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / All

'Directives' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
directives,
priorityLevels: [ currentPriorityLevel, ...nextPriorityLevels ],
element,
Expand All @@ -349,7 +350,7 @@
scope.attributes = element.props;

// Recursively render the wrapper for the next priority level.
const children =

Check failure on line 353 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 6

'children' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Check failure on line 353 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 7

'children' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Check failure on line 353 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 8

'children' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Check failure on line 353 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Build JavaScript assets for PHP unit tests

'children' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Check failure on line 353 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 5

'children' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Check failure on line 353 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 2

'children' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Check failure on line 353 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 4

'children' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Check failure on line 353 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 1

'children' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Check failure on line 353 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 3

'children' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Check failure on line 353 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Build Release Artifact

'children' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Check failure on line 353 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Run performance tests

'children' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Check failure on line 353 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / All

'children' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
nextPriorityLevels.length > 0
? createElement( Directives, {
directives,
Expand All @@ -360,7 +361,7 @@
} )
: element;

const props = { ...originalProps, children };

Check failure on line 364 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 6

'props' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Check failure on line 364 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 7

'props' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Check failure on line 364 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 8

'props' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Check failure on line 364 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Build JavaScript assets for PHP unit tests

'props' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Check failure on line 364 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 5

'props' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Check failure on line 364 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 2

'props' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Check failure on line 364 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 4

'props' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Check failure on line 364 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 1

'props' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Check failure on line 364 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 3

'props' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Check failure on line 364 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Build Release Artifact

'props' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Check failure on line 364 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Run performance tests

'props' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Check failure on line 364 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / All

'props' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
const directiveArgs = {
directives,
props,
Expand Down Expand Up @@ -391,7 +392,7 @@
const directives = props.__directives;
if ( directives.key ) {
vnode.key = directives.key.find(
( { suffix } ) => suffix === 'default'

Check failure on line 395 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 6

Binding element 'suffix' implicitly has an 'any' type.

Check failure on line 395 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 7

Binding element 'suffix' implicitly has an 'any' type.

Check failure on line 395 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 8

Binding element 'suffix' implicitly has an 'any' type.

Check failure on line 395 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Build JavaScript assets for PHP unit tests

Binding element 'suffix' implicitly has an 'any' type.

Check failure on line 395 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 5

Binding element 'suffix' implicitly has an 'any' type.

Check failure on line 395 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 2

Binding element 'suffix' implicitly has an 'any' type.

Check failure on line 395 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 4

Binding element 'suffix' implicitly has an 'any' type.

Check failure on line 395 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 1

Binding element 'suffix' implicitly has an 'any' type.

Check failure on line 395 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 3

Binding element 'suffix' implicitly has an 'any' type.

Check failure on line 395 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Build Release Artifact

Binding element 'suffix' implicitly has an 'any' type.

Check failure on line 395 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / Run performance tests

Binding element 'suffix' implicitly has an 'any' type.

Check failure on line 395 in packages/interactivity/src/hooks.tsx

View workflow job for this annotation

GitHub Actions / All

Binding element 'suffix' implicitly has an 'any' type.
).value;
}
delete props.__directives;
Expand Down
4 changes: 3 additions & 1 deletion packages/interactivity/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
45 changes: 25 additions & 20 deletions packages/interactivity/src/vdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions packages/interactivity/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"compilerOptions": {
"rootDir": "src",
"declarationDir": "build-types",

"noImplicitAny": false
"types": [ "gutenberg-env" ]
},
"include": [ "src/**/*" ]
}
Loading