deno_lint
deno_lint copied to clipboard
deno-lint does not support tracking `import =` syntax
Lint Name
no-unused-vars
Code Snippet
// deps.ts
export * as mongo from "https://deno.land/x/[email protected]/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 https://github.com/microsoft/TypeScript/issues/2552#issuecomment-87893040 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.Collectiondoes not work, because const only copymongo.Collection's function constructortype Collection = mongo.Collectionalso does not work, becauseGeneric type 'Collection<T>' requires 1 type argument(s)=> import is the only solution
https://github.com/denoland/deno/issues/12395#issuecomment-940114515
We should actually provide diagnostics that flag import = syntax as not desired.
We should actually provide diagnostics that flag import = syntax as not desired.
acording to https://github.com/denoland/deno/issues/12395#issuecomment-940599288
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/[email protected]/mod.ts"; import MongoClient = mongo.MongoClient; const mongoClient = new MongoClient(); Expected output (tsc):
import * as mongo from "https://deno.land/x/[email protected]/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?