admin管理员组

文章数量:1123694

I want to import the type of Deno.connect() argument. In VSCode, it shows the type is ConnectOptions defined in lib.deno.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...

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...

Share Improve this question edited 8 hours ago Jackoo asked yesterday JackooJackoo 2991 gold badge3 silver badges15 bronze badges 1
  • Please edit the question to include a minimal reproducible example. The default type-checking environment used by deno check already includes those types in the ambient scope (so there's no need to import them). – jsejcksn Commented 14 hours ago
Add a comment  | 

1 Answer 1

Reset to default 0

The builtin types can be referred from the Deno global

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

本文标签: typescriptHow to import a Deno builtin typeand still be able to run deno checkStack Overflow