dnt
dnt copied to clipboard
`typeCheck` fails unexpectedly
I'm wondering whether there's a way to disable typechecking of specific outputs? / what is the recommended approach to addressing the following (I'm making use of the ws and Deno shims, as well as the Deno std lib)?
src/_dnt.shims.ts:3:38 - error TS7016: Could not find a declaration file for module 'ws'. '/Users/harrysolovay/Desktop/capi/target/npm/node_modules/ws/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/ws` if it exists or add a new declaration (.d.ts) file containing `declare module 'ws';`
3 import { default as WebSocket } from "ws";
~~~~
src/_dnt.shims.ts:4:38 - error TS7016: Could not find a declaration file for module 'ws'. '/Users/harrysolovay/Desktop/capi/target/npm/node_modules/ws/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/ws` if it exists or add a new declaration (.d.ts) file containing `declare module 'ws';`
4 export { default as WebSocket } from "ws";
~~~~
src/deps/deno.land/[email protected]/async/debounce.ts:55:5 - error TS2322: Type 'Timeout' is not assignable to type 'number'.
55 timeout = setTimeout(flush, wait);
~~~~~~~
src/deps/deno.land/[email protected]/async/pool.ts:67:10 - error TS7053: Element implicitly has an 'any' type because expression of type 'unique symbol' can't be used to index type 'ReadableStream<R>'.
Property '[SymbolConstructor.asyncIterator]' does not exist on type 'ReadableStream<R>'.
67 return res.readable[Symbol.asyncIterator]();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/hashers/mod.ts:2:29 - error TS2307: Cannot find module './mod.generated.js' or its corresponding type declarations.
2 import { instantiate } from "./mod.generated.js";
~~~~~~~~~~~~~~~~~~~~
src/ss58/mod.ts:3:29 - error TS2307: Cannot find module './mod.generated.js' or its corresponding type declarations.
3 import { instantiate } from "./mod.generated.js";
~~~~~~~~~~~~~~~~~~~~
src/test-util/node.ts:13:23 - error TS2694: Namespace '"/Users/harrysolovay/Desktop/capi/target/npm/node_modules/@deno/shim-deno-test/dist/test"' has no exported member 'Process'.
13 inner: dntShim.Deno.Process;
~~~~~~~
src/test-util/node.ts:24:34 - error TS2339: Property 'run' does not exist on type 'typeof import("/Users/harrysolovay/Desktop/capi/target/npm/node_modules/@deno/shim-deno-test/dist/test")'.
24 const process = dntShim.Deno.run({
~~~
src/test-util/node.ts:41:22 - error TS2339: Property 'stdout' does not exist on type 'typeof import("/Users/harrysolovay/Desktop/capi/target/npm/node_modules/@deno/shim-deno-test/dist/test")'.
41 dntShim.Deno.stdout.write(log);
~~~~~~
src/test-util/node.ts:58:35 - error TS2339: Property 'errors' does not exist on type 'typeof import("/Users/harrysolovay/Desktop/capi/target/npm/node_modules/@deno/shim-deno-test/dist/test")'.
58 if (e instanceof dntShim.Deno.errors.NotFound) {
~~~~~~
src/test-util/sr25519/mod.ts:3:29 - error TS2307: Cannot find module './mod.generated.js' or its corresponding type declarations.
3 import { instantiate } from "./mod.generated.js";
~~~~~~~~~~~~~~~~~~~~
src/util/isPortAvailable.ts:4:35 - error TS2339: Property 'listen' does not exist on type 'typeof import("/Users/harrysolovay/Desktop/capi/target/npm/node_modules/@deno/shim-deno-test/dist/test")'.
4 const listener = dntShim.Deno.listen({
~~~~~~
src/util/isPortAvailable.ts:12:39 - error TS2339: Property 'errors' does not exist on type 'typeof import("/Users/harrysolovay/Desktop/capi/target/npm/node_modules/@deno/shim-deno-test/dist/test")'.
12 if (error instanceof dntShim.Deno.errors.AddrInUse) {
~~~~~~
error: Uncaught (in promise) Error: Had 13 diagnostics.
throw new Error(`Had ${diagnostics.length} diagnostics.`);
^
at build (https://deno.land/x/[email protected]/mod.ts:293:15)
at async Promise.all (index 0)
at async file:///Users/harrysolovay/Desktop/capi/_tasks/dnt.ts:9:1
Also, mod.generated.js
contains JSDoc annotations (is actually the output of wasmbuild).
Any thoughts?
Try:
- Add
@types/ws
as a dev dependency - Use the "timers" shim: https://github.com/denoland/dnt#built-in-shims
- Use the full "deno" shim and not just the test one.
Not sure about the other ones.
Gotcha. Thank you for the suggestions. Some new issues cropped up. Going to disable the type-check.
For those interested in the new errors...
src/deps_2/deno.land/[email protected]/async/pool.ts:63:13 - error TS2304: Cannot find name 'AggregateError'.
63 new AggregateError(errors, "Threw while mapping."),
~~~~~~~~~~~~~~
src/deps_2/deno.land/[email protected]/async/pool.ts:67:10 - error TS7053: Element implicitly has an 'any' type because expression of type 'unique symbol' can't be used to index type 'ReadableStream<R>'.
Property '[SymbolConstructor.asyncIterator]' does not exist on type 'ReadableStream<R>'.
67 return res.readable[Symbol.asyncIterator]();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/deps_2/deno.land/[email protected]/testing/_diff.ts:245:8 - error TS2550: Property 'replaceAll' does not exist on type 'string'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2021' or later.
245 .replaceAll("\b", "\\b")
~~~~~~~~~~
src/deps_2/deno.land/[email protected]/testing/_diff.ts:251:10 - error TS7006: Parameter 'str' implicitly has an 'any' type.
251 (str) => str === "\r" ? "\\r" : str === "\n" ? "\\n\n" : "\\r\\n\r\n",
~~~
src/deps_2/deno.land/[email protected]/testing/asserts.ts:204:24 - error TS2304: Cannot find name 'WeakRef'.
204 if (a instanceof WeakRef || b instanceof WeakRef) {
~~~~~~~
src/deps_2/deno.land/[email protected]/testing/asserts.ts:204:48 - error TS2304: Cannot find name 'WeakRef'.
204 if (a instanceof WeakRef || b instanceof WeakRef) {
~~~~~~~
src/deps_2/deno.land/[email protected]/testing/asserts.ts:205:28 - error TS2304: Cannot find name 'WeakRef'.
205 if (!(a instanceof WeakRef && b instanceof WeakRef)) return false;
~~~~~~~
src/deps_2/deno.land/[email protected]/testing/asserts.ts:205:52 - error TS2304: Cannot find name 'WeakRef'.
205 if (!(a instanceof WeakRef && b instanceof WeakRef)) return false;
~~~~~~~
src/deps_2/deno.land/[email protected]/testing/asserts.ts:206:26 - error TS2339: Property 'deref' does not exist on type 'object'.
206 return compare(a.deref(), b.deref());
~~~~~
src/deps_2/deno.land/[email protected]/testing/asserts.ts:206:37 - error TS2339: Property 'deref' does not exist on type 'object'.
206 return compare(a.deref(), b.deref());
@harrysolovay Do you have esnext
at compilerOptions.lib
? Reference: https://stackoverflow.com/a/66256279/228885 . I think that should help with WeakRef
at least and maybe with the others too.
I resolved most of the errors by following David's advice (adding the @types
dev deps). Specifying the esnext
lib resolved a few as well (thank you!).
Still running into the following:
src/deps_2/deno.land/[email protected]/async/pool.ts:67:10 - error TS7053: Element implicitly has an 'any' type because expression of type 'unique symbol' can't be used to index type 'ReadableStream<R>'.
Property '[SymbolConstructor.asyncIterator]' does not exist on type 'ReadableStream<R>'.
67 return res.readable[Symbol.asyncIterator]();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: Uncaught (in promise) Error: Had 1 diagnostics.
throw new Error(`Had ${diagnostics.length} diagnostics.`);
^
at build (https://deno.land/x/[email protected]/mod.ts:293:15)
at async Promise.all (index 0)
at async file:///Users/harrysolovay/Desktop/capi/_tasks/dnt.ts:9:1
I attempted to resolve this by adding the esnext.asynciterable
lib, but it did not work. Is there another lib that needs to be enabled?
Aside from this one error, all others are resolved.
Solution credit to oak: https://github.com/oakserver/oak/pull/479/files#diff-a150fb53afee945f23f3fe7c176007111f3ba81bb0d188af4077d4a0fc4caa37
Added a custom shim:
shims: {
deno: true,
timers: true,
+ custom: [{
+ package: { name: "stream/web" },
+ globalNames: ["TransformStream"],
+ }],
},
Everything checks successfully!
I should have confirmed the correct runtime behavior:
error - ./node_modules/capi/esm/_dnt.shims.js:5:0
Module not found: Can't resolve 'stream/web'
Import trace for requested module:
./node_modules/capi/esm/deps_2/deno.land/[email protected]/testing/asserts.js
./node_modules/capi/esm/deps/std/testing/asserts.js
./node_modules/capi/esm/fluent/Address.js
./node_modules/capi/esm/fluent/mod.js
./node_modules/capi/esm/mod.js
./pages/index.tsx
Unfortunately, I'm back to disabling DNT type checking :/