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

type of dynamic url imports nested in a dynamic import always resolves to any #20294

Closed
scarf005 opened this issue Aug 26, 2023 · 2 comments · Fixed by #20342
Closed

type of dynamic url imports nested in a dynamic import always resolves to any #20294

scarf005 opened this issue Aug 26, 2023 · 2 comments · Fixed by #20342
Assignees
Labels
bug Something isn't working correctly fix available there is a fix available in a third party library that needs to be merged swc related to swc (bundling/transpiling)

Comments

@scarf005
Copy link
Contributor

scarf005 commented Aug 26, 2023

Summary

type of dynamic imports from URL like import("https://<url>").Member are always any.

Reproduction

image

// @deno-types="https://esm.sh/v131/@octokit/[email protected]/dist-types/index.d.ts"
import { Octokit } from "https://esm.sh/@octokit/[email protected]"
import type { AssertFalse, IsAny } from "https://deno.land/[email protected]/testing/types.ts"

type _ = AssertFalse<IsAny<Octokit>>

(adding @deno-types makes no differences)

 ~/r/d/test  deno check main.ts     2023년 08월 27일 (일) 오전 12시 25분 43초
Check file:///home/scarf/repo/deno-packages/test/main.ts
error: TS2344 [ERROR]: Type 'true' does not satisfy the constraint 'false'.
type _ = AssertFalse<IsAny<Octokit>>
                     ~~~~~~~~~~~~~~
    at file:///home/scarf/repo/deno-packages/test/main.ts:5:22

this does not seem to be a esm.sh problem as manually converting dynamic imports to import statement works:

// typechecks
import { Constructor } from "https://esm.sh/v131/@octokit/[email protected]/dist-types/types.d.ts"
import { PaginateInterface } from "https://esm.sh/v131/@octokit/[email protected]/dist-types/index.d.ts"
import { RestEndpointMethods } from "https://esm.sh/v131/@octokit/[email protected]/dist-types/generated/method-types.d.ts"
import { Api } from "https://esm.sh/v131/@octokit/[email protected]/dist-types/types.d.ts"

import { Octokit as Core } from "https://esm.sh/v131/@octokit/[email protected]/dist-types/index.d.ts"
export type { RestEndpointMethodTypes } from "https://esm.sh/v131/@octokit/[email protected]/dist-types/index.d.ts"
export declare const Octokit:
	& typeof Core
	& Constructor<{ paginate: PaginateInterface } & RestEndpointMethods & Api>
export type Octokit = InstanceType<typeof Octokit>

import type { AssertFalse, IsAny } from "https://deno.land/[email protected]/testing/types.ts"

type _ = AssertFalse<IsAny<Octokit>>

npm: works:

image

// typechecks
import { Octokit } from "npm:@octokit/[email protected]"
import type { AssertFalse, IsAny } from "https://deno.land/[email protected]/testing/types.ts"

type _ = AssertFalse<IsAny<Octokit>>
@dsherret dsherret added the bug Something isn't working correctly label Aug 28, 2023
@dsherret
Copy link
Member

Looks like the swc module analysis has a bug on that file. It's missing paginate:

{
  "dependencies": [
    {
      "kind": "import",
      "range": {
        "start": { "line": 0, "character": 0 },
        "end": { "line": 0, "character": 96 }
      },
      "specifier": "https://esm.sh/v131/@octokit/[email protected]/dist-types/index.d.ts",
      "specifierRange": {
        "start": { "line": 0, "character": 32 },
        "end": { "line": 0, "character": 95 }
      }
    },
    {
      "kind": "exportType",
      "range": {
        "start": { "line": 1, "character": 0 },
        "end": { "line": 1, "character": 133 }
      },
      "specifier": "https://esm.sh/v131/@octokit/[email protected]/dist-types/index.d.ts",
      "specifierRange": {
        "start": { "line": 1, "character": 45 },
        "end": { "line": 1, "character": 132 }
      }
    },
    {
      "kind": "importType",
      "range": {
        "start": { "line": 2, "character": 44 },
        "end": { "line": 4, "character": 239 }
      },
      "specifier": "https://esm.sh/v131/@octokit/[email protected]/dist-types/types.d.ts",
      "specifierRange": {
        "start": { "line": 2, "character": 51 },
        "end": { "line": 2, "character": 114 }
      }
    }
  ]
}

@dsherret dsherret self-assigned this Aug 28, 2023
@dsherret
Copy link
Member

I opened swc-project/swc#7883

@dsherret dsherret added swc related to swc (bundling/transpiling) fix available there is a fix available in a third party library that needs to be merged labels Aug 28, 2023
@dsherret dsherret changed the title type of dynamic url imports in d.ts always resolves to any type of dynamic url imports nested in a dynamic import always resolves to any Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly fix available there is a fix available in a third party library that needs to be merged swc related to swc (bundling/transpiling)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants