microsoft / microsoft/TypeScript

NodeList should be generic instead of having NodeListOf

Abierto
#53,540 1 comentario 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Awaiting More Feedback Suggestion
Lenguaje dominante
Go
Estrellas
111k
Forks
14.4k
Merge medio
1 d 19 h
PR fusionados (30 d)
117

Descripción

lib Update Request

I may be missing something, but I don't see why NodeListOf exists instead of just having NodeList itself be generic. Maybe it's a vestige from a time before generic parameter defaults.

NodeList should be able to be generic with a default value of Node.

Configuration Check

afaik, this is true of all versions of lib.dom.ts. I've checked up to 5.0

Missing / Incorrect Definition

I think this should be a backwards compatible change:

interface NodeList<TNode extends Node = Node> {
  readonly length: number;
  item(index: number): TNode | null;
  forEach(callbackfn: (value: TNode, key: number, parent: NodeList<TNode>) => void, thisArg?: any): void;
  [index: number]: TNode;
}

/** @deprecated Use NodeList */
interface NodeListOf<TNode extends Node> extends NodeList<TNode> {
  item(index: number): TNode;
}

Sample Code

let getDivs = (): NodeList<HTMLDivElement> => {/* ... */};

Documentation Link

N/A though removing NodeListOf would remove a type that's only present in lid.dom.d.ts, not the actual DOM APIs.

Guía de contribución

Abrir la guía de contribución

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.

Línea de trabajo

Comienza en lib.dom.ts y localiza las declaraciones de NodeList y NodeListOf. Compáralas con el valor predeterminado genérico solicitado y el alias de compatibilidad obsoleto; el trabajo estará terminado cuando NodeList admita el uso mostrado de HTMLDivElement y el código existente de NodeListOf siga siendo compatible.

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

Evaluación

Stack tecnológico
typescript
Área
tooling
Tipo de issue
Refactorización
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.