Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

[Web API type definition issue] `exactOptionalPropertyTypes` makes working with most of the interfaces a nightmare

Abierto
#2,119 5 comentarios 3 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
typescript
Área
api, web-dev

Línea de trabajo

Empieza examinando el archivo lib.dom.d.ts generado y las definiciones del diccionario de Web API relacionadas con RequestInit, usando el ejemplo de Playground proporcionado con exactOptionalPropertyTypes habilitado. Se considera terminado cuando las propiedades opcionales de Web API acepten correctamente undefined cuando las reglas de Web IDL lo traten como una propiedad omitida, sin romper las definiciones generadas.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

lib.d.ts bug
Summary

Optional fields in lib.dom.d.ts do not explicity have undefined in their types, which makes their construction needlessly difficult

Expected vs. Actual Behavior

Expected following code to just work:

function fetchUsers(params?: { signal?: AbortSignal | undefined }) {
  return fetch("/api/v1/user/", { signal: params?.signal });
}

But instead the following error is shown:

Argument of type '{ signal: AbortSignal | undefined; }' is not assignable to parameter of type 'RequestInit' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
  Types of property 'signal' are incompatible.
    Type 'AbortSignal | undefined' is not assignable to type 'AbortSignal | null'.
      Type 'undefined' is not assignable to type 'AbortSignal | null'. (2379)

Following is required to be done instead (let's pretend that RequestInit.signal cannot be set to null):

function fetchUsers(params?: { signal?: AbortSignal | undefined }) {
  const init: RequestInit = {};
  if (params?.signal) {
    init.signal = params.signal;
  }

  return fetch("/api/v1/user/", init);
}
Playground Link

https://www.typescriptlang.org/play/?exactOptionalPropertyTypes=true#code/GYVwdgxgLglg9mABMAplCALAqgZxQJxwAoAHAQ3zIFscB+ALkQG9EcYBzMMgGwcQEEARnHxQAyhy7dEAH0TgAJimAwwKBYgC+ASmYAoRInxoQ+JKnQYiAIgD0ZEjFsA3AIy2QefLesAaZqySPIzklDS0AHRsnDxa2gDceppAA

Browser Support
  • This API is supported in at least two major browser engines (not two Chromium-based browsers).
Have Tried The Latest Releases
  • This issue applies to the latest release of TypeScript.
  • This issue applies to the latest release of @types/web.
Additional Context

See https://webidl.spec.whatwg.org/#idl-dictionaries:

In the JavaScript binding, a value of undefined for the property corresponding to a dictionary member is treated the same as omitting that property.

I have not found a single | undefined on an optional interface field in the entire lib.dom.d.ts of Typescript 5.9.2.

Lenguaje dominante
TypeScript
Estrellas
740
Forks
474
Merge medio
2 d 8 h
PR fusionados (30 d)
15

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de microsoft/TypeScript-DOM-lib-generator

Todos los issues de microsoft/TypeScript-DOM-lib-generator

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.