typescriptdeno

How to import a Deno builtin type, and still be able to run deno check?


I want to import the type of Deno.connect() argument. In VSCode, it shows the type is ConnectOptions defined in lib.deno.net.d.ts. I use deno types > lib.deno.d.ts to generate the ts file so that other files can import the types. But then deno check/deno compile reports duplicate identifier errors. How can I import a Deno builtin type, and still be able to run commands like deno check?

Example code:
Case 1, no import

// main.ts
export function f(options: ConnectOptions) {
}

deno check main.ts result:

error: TS2304 [ERROR]: Cannot find name 'ConnectOptions'.

Case 2, run deno types > lib.deno.d.ts and add import

// main.ts
import type { ConnectOptions } from "./lib.deno.d.ts"

export function f(options: ConnectOptions) {
}

deno check main.ts result:

error: TS2300 [ERROR]: Duplicate identifier 'Addr'. export type Addr = NetAddr | UnixAddr;
other duplicate identifier errors...


Solution

  • The builtin types can be referred from the Deno global

    export function f(options: Deno.ConnectOptions) {
    }