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

Importing JavaScript modules throws type errors #1239

Closed
thysultan opened this issue Nov 29, 2018 · 7 comments
Closed

Importing JavaScript modules throws type errors #1239

thysultan opened this issue Nov 29, 2018 · 7 comments

Comments

@thysultan
Copy link

Given the following script:

import * as dyo from 'https://unpkg.com/dyo?module'

console.log(dyo)

Produces the following error:

HttpUser: client requires absolute-form URIs
    at maybeError (deno/js/errors.ts:38:12)
    at maybeThrowError (deno/js/errors.ts:26:15)
    at sendSync (deno/js/dispatch.ts:67:5)
    at Object.codeFetch (deno/js/os.ts:41:19)
    at DenoCompiler.resolveModule (deno/js/compiler.ts:569:38)
    at moduleNames.map.name (deno/js/compiler.ts:721:31)
    at Array.map (<anonymous>)
    at DenoCompiler.resolveModuleNames (deno/js/compiler.ts:713:24)
    at Object.compilerHost.resolveModuleNames (<anonymous>)
    at resolveModuleNamesWorker (<anonymous>)

When altered to use the resolved url:

import * as dyo from 'https://unpkg.com/[email protected]/dist/dyo.esm.js?module'

console.log(dyo)

Typescript throws type related errors for this non-TypeScript import.

@kevinkassimo
Copy link
Contributor

I think there are actually 2 separate issues related to this.

  1. Deno fails to treat relative Location header URI properly. I'll do a fix for this tomorrow.
  2. Some compile time issues. @kitsonk

@kitsonk
Copy link
Contributor

kitsonk commented Nov 29, 2018

Can you post the related errors? TypeScript does the transpiling of modules and Check JS is on by default. Until we have #51, and CheckJS could be turned off this would likely require this in the module:

// @ts-nocheck

@thysultan
Copy link
Author

@kitsonk

Warning: Large dump of text
~/.deno/deps/https/unpkg.com/[email protected]/dist/dyo.esm.js:1:281 - error TS2339: Property 'iterator' does not exist on type 'SymbolConstructor | (() => number)'.
  Property 'iterator' does not exist on type '() => number'.

1 var math = Math;var random = math.random;var object = Object;var hop = object.hasOwnProperty;var create = object.create;var property = object.defineProperty;var properties = object.defineProperties;var symbol = typeof Symbol === "function" ? Symbol : random;var iterator = symbol.iterator || "@@iterator";var asyncIterator = symbol.asyncIterator || "@@asyncIterator";function timeout(e, t) {
~~~~~~~~
~/.deno/deps/https/unpkg.com/[email protected]/dist/dyo.esm.js:1:333 - error TS2339: Property 'asyncIterator' does not exist on type 'SymbolConstructor | (() => number)'.
Property 'asyncIterator' does not exist on type '() => number'.

1 var math = Math;var random = math.random;var object = Object;var hop = object.hasOwnProperty;var create = object.create;var property = object.defineProperty;var properties = object.defineProperties;var symbol = typeof Symbol === "function" ? Symbol : random;var iterator = symbol.iterator || "@@iterator";var asyncIterator = symbol.asyncIterator || "@@asyncIterator";function timeout(e, t) {
~~~~~~~~~~~~~
~/.deno/deps/https/unpkg.com/[email protected]/dist/dyo.esm.js:55:18 - error TS2403: Subsequent variable declarations must have the same type. Variable 'o' must be of type 'number', but here has type 'any'.

55 for (var o = n, i = sequence(t), a = i.next(); !a.done; ++o) {
~
~/.deno/deps/https/unpkg.com/[email protected]/dist/dyo.esm.js:80:17 - error TS2580: Cannot find name 'process'. Do you need to install type definitions for node? Try npm i @types/node.

80 return typeof process !== "object" ? "" : typeof process.env !== "object" ? process.env : process.env.NODE_ENV + "";
~~~~~~~
~/.deno/deps/https/unpkg.com/[email protected]/dist/dyo.esm.js:80:52 - error TS2580: Cannot find name 'process'. Do you need to install type definitions for node? Try npm i @types/node.

80 return typeof process !== "object" ? "" : typeof process.env !== "object" ? process.env : process.env.NODE_ENV + "";
~~~~~~~
~/.deno/deps/https/unpkg.com/[email protected]/dist/dyo.esm.js:80:79 - error TS2580: Cannot find name 'process'. Do you need to install type definitions for node? Try npm i @types/node.

80 return typeof process !== "object" ? "" : typeof process.env !== "object" ? process.env : process.env.NODE_ENV + "";
~~~~~~~
~/.deno/deps/https/unpkg.com/[email protected]/dist/dyo.esm.js:80:93 - error TS2580: Cannot find name 'process'. Do you need to install type definitions for node? Try npm i @types/node.

80 return typeof process !== "object" ? "" : typeof process.env !== "object" ? process.env : process.env.NODE_ENV + "";
~~~~~~~
~/.deno/deps/https/unpkg.com/[email protected]/dist/dyo.esm.js:125:23 - error TS2584: Cannot find name 'document'. Do you need to change your target library? Try changing the lib compiler option to include 'dom'.

125 } else if (typeof document === "object") {
~~~~~~~~
~/.deno/deps/https/unpkg.com/[email protected]/dist/dyo.esm.js:126:26 - error TS2584: Cannot find name 'document'. Do you need to change your target library? Try changing the lib compiler option to include 'dom'.

126 return target$1(e, document);
~~~~~~~~
~/.deno/deps/https/unpkg.com/[email protected]/dist/dyo.esm.js:188:11 - error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((e: any) => any) | ((key: object) => any)' has no compatible call signatures.

188 var o = Registry.get(n);if (!o) {
~~~~~~~~~~~~~~~
~/.deno/deps/https/unpkg.com/[email protected]/dist/dyo.esm.js:189:5 - error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((e: any, t: any) => { key: number | symbol; has: (e: any) => any; get: (e: any) => any; set: any; }) | ((key: object, value: any) => WeakMap<object, any>)' has no compatible call signatures.

189 Registry.set(n, o = {});
~~~~~~~~~~~~~~~~~~~~~~~
~/.deno/deps/https/unpkg.com/[email protected]/dist/dyo.esm.js:194:10 - error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((e: any) => any) | ((key: object) => any)' has no compatible call signatures.

194 return Registry.get(t)[e.type];
~~~~~~~~~~~~~~~
~/.deno/deps/https/unpkg.com/[email protected]/dist/dyo.esm.js:326:18 - error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((e: any, t: any) => { key: number | symbol; has: (e: any) => any; get: (e: any) => any; set: any; }) | ((key: object, value: any) => WeakMap<object, any>)' has no compatible call signatures.

326 this.error = n;Registry.set(this, t);
~~~~~~~~~~~~~~~~~~~~~
~/.deno/deps/https/unpkg.com/[email protected]/dist/dyo.esm.js:330:20 - error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((e: any) => any) | ((key: object) => any)' has no compatible call signatures.

330 return trace(Registry.get(this), "");
~~~~~~~~~~~~~~~~~~
~/.deno/deps/https/unpkg.com/[email protected]/dist/dyo.esm.js:410:41 - error TS2447: The '|' operator is not allowed for boolean types. Consider using '||' instead.

410 update(e, t, n, d, h, r, u);if (++u > l | ++c > p) {
~~~~~~~~~~~~~~~~~
~/.deno/deps/https/unpkg.com/[email protected]/dist/dyo.esm.js:414:41 - error TS2447: The '|' operator is not allowed for boolean types. Consider using '||' instead.

414 update(e, t, n, v, $, r, l);if (u > --l | c > --p) {
~~~~~~~~~~~~~~~~~
~/.deno/deps/https/unpkg.com/[email protected]/dist/dyo.esm.js:436:38 - error TS2447: The '|' operator is not allowed for boolean types. Consider using '||' instead.

436 m = {}, g = {}, b = 0;while (i > u | a > c) {
~~~~~~~~~~~~~
~/.deno/deps/https/unpkg.com/[email protected]/dist/dyo.esm.js:525:25 - error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((e: any) => any) | ((key: object) => any)' has no compatible call signatures.

525 return dispatch$2(Registry.get(this), this, e, t);
~~~~~~~~~~~~~~~~~~
~/.deno/deps/https/unpkg.com/[email protected]/dist/dyo.esm.js:545:11 - error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((e: any) => any) | ((key: object) => any)' has no compatible call signatures.

545 }return Registry.get(e) || Registry.set(e, from$1(e)).get(e);
~~~~~~~~~~~~~~~
~/.deno/deps/https/unpkg.com/[email protected]/dist/dyo.esm.js:545:30 - error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((e: any, t: any) => { key: number | symbol; has: (e: any) => any; get: (e: any) => any; set: any; }) | ((key: object, value: any) => WeakMap<object, any>)' has no compatible call signatures.

545 }return Registry.get(e) || Registry.set(e, from$1(e)).get(e);
~~~~~~~~~~~~~~~~~~~~~~~~~~
~/.deno/deps/https/unpkg.com/[email protected]/dist/dyo.esm.js:569:272 - error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((e: any, t: any) => { key: number | symbol; has: (e: any) => any; get: (e: any) => any; set: any; }) | ((key: object, value: any) => WeakMap<object, any>)' has no compatible call signatures.

569 var o = r.type;var i = r.props;var a = r.context = t.context = t.context || {};var u = identity(o, o.prototype);var c = r.instance = new u(i);var s = c.state || {};var f = r.children;var l = r;types(r, a, contextTypes);c.props = i;c.state = s;c.context = a;c.refs = {};Registry.set(c, r);if (has$1(c, getDerivedState)) {
~~~~~~~~~~~~~~~~~~
~/.deno/deps/https/unpkg.com/[email protected]/dist/dyo.esm.js:762:7 - error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((e: any) => any) | ((key: object) => boolean)' has no compatible call signatures.

762 if (Registry.has(t)) {
~~~~~~~~~~~~~~~
~/.deno/deps/https/unpkg.com/[email protected]/dist/dyo.esm.js:763:32 - error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((e: any) => any) | ((key: object) => any)' has no compatible call signatures.

763 return checkout(enqueue$4, Registry.get(t), t, [root(e)], n);
~~~~~~~~~~~~~~~
~/.deno/deps/https/unpkg.com/[email protected]/dist/dyo.esm.js:774:24 - error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((e: any, t: any) => { key: number | symbol; has: (e: any) => any; get: (e: any) => any; set: any; }) | ((key: object, value: any) => WeakMap<object, any>)' has no compatible call signatures.

774 create$3(e, t, t, t);Registry.set(n, t);

@kitsonk
Copy link
Contributor

kitsonk commented Nov 29, 2018

Yeah, it is exactly that, in that Check JS is stopping this.

@bartlomieju
Copy link
Member

I can't reproduce this issue on v0.2.11. @kitsonk do you think we can close this?

@kitsonk
Copy link
Contributor

kitsonk commented Feb 12, 2019

Well we just disabled CheckJS, so the underlying issue isn't resolved. But I guess it will be a while before we add that back.

@bartlomieju
Copy link
Member

With Deno v0.13.0 I get following output:

{ Boundary, Children, Fragment, Suspense, cloneElement, createElement, createPortal, h, isValidElement, lazy, memo, render, useCallback, useContext, useEffect, useLayout, useMemo, useReducer, useRef, useState }

I think we can close this issue now.

CC @ry

@ry ry closed this as completed Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants