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

deno-lint does not support tracking import = syntax #934

Open
lts20050703 opened this issue Oct 11, 2021 · 3 comments
Open

deno-lint does not support tracking import = syntax #934

lts20050703 opened this issue Oct 11, 2021 · 3 comments

Comments

@lts20050703
Copy link

lts20050703 commented Oct 11, 2021

Lint Name

no-unused-vars

Code Snippet

// deps.ts
export * as mongo from "https://deno.land/x/mongo@v0.27.0/mod.ts"
// mongo.ts
import { mongo } from "./deps.ts"
import MongoClient = mongo.MongoClient
const mongoClient = new MongoClient()

Expected Result

No warning

Actual Result

(no-unused-vars) `mongo` is never used
import { mongo } from "./deps.ts"
         ^^^^^
    at /home/lts372005/Desktop/discordeno-kingdoms/mongo.ts:1:9

    hint: If this is intentional, alias it with an underscore like `mongo as _mongo`
    help: for further information visit https://lint.deno.land/#no-unused-vars

Found 1 problem
Checked 9 files

Version

deno 1.14.3 (release, x86_64-unknown-linux-gnu)
v8 9.4.146.19
typescript 4.4.2

Why I import Collection = mongo.Collection and not type Collection = mongo.Collection (or in the case of denoland/deno#12395, why not const Collection = mongo.Collection)

Read microsoft/TypeScript#2552 (comment)
TL;DR Consider the following

import { mongo } from "../deps.ts"
import Collection = mongo.Collection
import Filter = mongo.Filter
export default function<type>(collection: Collection<type>, filter: Filter<type>) {
	return collection.findOne(filter, { noCursorTimeout: false })
}
  • const Collection = mongo.Collection does not work, because const only copy mongo.Collection's function constructor
  • type Collection = mongo.Collection also does not work, because Generic type 'Collection<T>' requires 1 type argument(s)
    => import is the only solution
@lts20050703 lts20050703 added the bug Something isn't working label Oct 11, 2021
@lts20050703 lts20050703 changed the title export * as ns from "" then import {ns} from "" warn no-unused-vars even though I do export * as ns, then import {ns}, then ns.a warn unused variables even though I do Oct 11, 2021
@lts20050703
Copy link
Author

@kitsonk kitsonk changed the title export * as ns, then import {ns}, then ns.a warn unused variables even though I do deno-lint does not support tracking import = syntax Oct 12, 2021
@kitsonk kitsonk added design limitation Currently this is a limitation of the design and removed bug Something isn't working labels Oct 12, 2021
@kitsonk
Copy link
Contributor

kitsonk commented Oct 12, 2021

We should actually provide diagnostics that flag import = syntax as not desired.

@lts20050703
Copy link
Author

We should actually provide diagnostics that flag import = syntax as not desired.

acording to denoland/deno#12395 (comment)

They are different syntaxes: https://www.typescriptlang.org/docs/handbook/namespaces.html#aliases

Another way that you can simplify working with namespaces is to use import q = x.y.z to create shorter names for commonly-used objects. Not to be confused with the import x = require("name") syntax used to load modules, this syntax simply creates an alias for the specified symbol.

Babel is fine with aliases.

I just found the fix you recently pushed for this swc-project/swc#2234 / swc-project/swc#2249 which has already landed in Deno canary. There is still a bug, though.

Input:

import * as mongo from "https://deno.land/x/mongo@v0.27.0/mod.ts";
import MongoClient = mongo.MongoClient;
const mongoClient = new MongoClient();
Expected output (tsc):

import * as mongo from "https://deno.land/x/mongo@v0.27.0/mod.ts";
var MongoClient = mongo.MongoClient;
const mongoClient = new MongoClient();
Actual output on canary (--no-check, swc):

var MongoClient = mongo.MongoClient;
const mongoClient = new MongoClient();
The import was stripped because the rhs of import MongoClient = mongo.MongoClient wasn't registered as a value usage of mongo.

@kitsonk consider remove the design limitation label?

@bartlomieju bartlomieju removed the design limitation Currently this is a limitation of the design label Oct 12, 2021
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

3 participants