Files
scriptc/packages/compiler/ambient/node-fallback/dns.d.ts
T
Chris Tate f0f91ac1ff Load a Node module's fallback declarations only when the program names it
Without @types/node, every program loaded scriptc-node-fallback.d.ts whole:
the console and process globals and 47 Node modules, about 8,100 lines,
parsed, bound and checked in every cold build whether or not the program
imported them.

- The fallback file keeps the globals and the modules they name (console,
  readline, readline/promises, perf_hooks, tty). Every other module, under
  both spellings, has its own file in ambient/node-fallback/, which
  references the files of the modules its declarations name.
- A module's file joins the program when one of the program's files names
  the module in a string literal: imports, requires, import types and JSDoc
  types all name modules that way. The entry is read before the first
  program; the program-root discovery passes add modules that other files
  name. Files are read as tsgo reads them, and the TypeScript libraries and
  scriptc's own declarations are skipped.
- The checks that recognized the fallback file by its path recognize every
  fallback file.
2026-10-25 15:36:08 -05:00

66 lines
2.4 KiB
TypeScript

/// <reference path="./dns-promises.d.ts" />
/* node:dns — the lookup slice (scr_dgram.c hosts it; getaddrinfo runs AT
* CALL TIME and the callback defers to the next loop turn — SEMANTICS.md
* documents the blocking divergence). Only the { family: 4 } options
* form lowers; failures deliver Node's error shape ("getaddrinfo
* ENOTFOUND <hostname>") as the callback's Error argument, with "" for
* the address where Node passes undefined. */
declare module "dns" {
export interface LookupAddress {
address: string;
family: number;
}
export interface LookupOptions {
family?: number | "IPv4" | "IPv6";
hints?: number;
all?: boolean;
order?: "ipv4first" | "ipv6first" | "verbatim";
verbatim?: boolean;
}
export interface LookupOneOptions extends LookupOptions {
all?: false;
}
export interface LookupAllOptions extends LookupOptions {
all: true;
}
/* The callback comes with the other lookup deliveries (literal
* addresses on the next tick); the options follow lib/dns.js. */
export function lookup(
hostname: string,
callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void,
): void;
export function lookup(
hostname: string,
family: number,
callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void,
): void;
export function lookup(
hostname: string,
options: LookupOneOptions,
callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void,
): void;
export function lookup(
hostname: string,
options: LookupAllOptions,
callback: (err: NodeJS.ErrnoException | null, addresses: LookupAddress[]) => void,
): void;
/* getnameinfo with NI_NAMEREQD: the host's name and the port's service
* name (the number when it has none). */
export function lookupService(
address: string,
port: number,
callback: (err: NodeJS.ErrnoException | null, hostname: string, service: string) => void,
): void;
/* The nameservers /etc/resolv.conf lists. */
export function getServers(): string[];
export function getDefaultResultOrder(): "ipv4first" | "ipv6first" | "verbatim";
export function setDefaultResultOrder(order: "ipv4first" | "ipv6first" | "verbatim"): void;
/* The promise forms (node:dns/promises). */
export const promises: typeof import("dns/promises");
}
declare module "node:dns" {
export * from "dns";
}