Tutorial - Test your app error on line 179

Has anyone encountered this error when completing the tutorial for test your app? as shown in the screenshot, parameter ‘n’ has an ‘any’ type. I am not sure what to do, any help?

I have not seen that one before. Generally speaking, different versions of the TypeScript compiler will infer different things, so it’s a bit tricky to keep this example working for everyone: older versions may not support newer syntax, newer versions may detect more typing issues (that in turn may require new syntax to fix).

In this case I believe you can solve the problem by adding a type annotation for n:

n: number => document...

Which version of typescript is working for you? mine is 4.9.4

As you can see from the template’s package.json, the file gets tested with 3.8.3, and that’s what gets used when you run npm test, which does not report any type error.

I can confirm, however, that in Visual Studio Code line 179 now gets reported as an error (it didn’t back when I last touched those tests, though that was a couple months ago now). I supppose VSCode gets its own version of typescript, and it’s a more recent one.

The correct form for line 179 is:

    (n: number) => document.querySelectorAll(".test-select-following").length == n,

I’ll make a PR to update our docs.

2 Likes

Yes it worked :+1:.
Thank you very much for the help Gary

1 Like