lib.d.ts types are too loose: provide a version without vars declared?
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- typescript
- Área
- tooling
Línea de trabajo
No se nombran archivos, pruebas ni puntos de entrada. Empieza por rastrear cómo este generador produce declaraciones de lib.d.ts y, después, determina cómo podría generarse una variante de solo tipos preservando las declaraciones globales existentes. Se considera terminado cuando el generador expone la separación solicitada y su salida generada valida el caso de uso de navegador frente a solo tipos descrito aquí.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
(Porting https://github.com/Microsoft/TypeScript/issues/20175)
A lot of teams have seen production bugs from trying to use code not available in older browsers. performance.now, for example, is listed in lib.d.ts but shouldn't be used on sites that support IE10 and don't polyfill performance.
Two other ways of getting around this class of problem without dropping browsers or adding polyfills (are there other good ones?) are:
- Manually banning scores of built-in types with TSLint
- Dropping
"dom"from"lib"intsconfig.json
Removing "dom" typings works great to enforce using only non-browser APIs (or dependency-injecting them where used), which is much better than calling APIs like performance.now and setTimeout willy nilly. However, you now need to manually re-write typings for all these native things as you go.
The solution would be much simpler if TypeScript exposed a form of lib.d.ts that included only the interfaces and types for all these constructs without the declare var/declare function.
Using setTimeout as an example, it's declared without a separate ISetTimeout interface in TypeScript's lib.d.ts:
declare function setTimeout(handler: (...args: any[]) => void, timeout: number): number;
declare function setTimeout(handler: any, timeout?: any, ...args: any[]): number;
interface WindowTimers extends Object, WindowTimersExtension {
// ...
setTimeout(handler: (...args: any[]) => void, timeout: number): number;
setTimeout(handler: any, timeout?: any, ...args: any[]): number;
}
If it were changed to provide an ISetTimeout it would be much easier to use setTimeout without a reliance on the browser+Node API.
interface SetTimeout {
(handler: (...args: any[]) => void, timeout: number): number;
(handler: any, timeout?: any, ...args: any[]): number;
}
interface WindowTimers extends Object, WindowTimersExtension {
// ...
setTimeout: SetTimeout;
}
// Only in the standard ("loose") version:
declare var setTimeout: SetTimeout;
Errata: I personally remove "dom" whenever possible.. but a lot of @types definitions assume it exists and it's a bit like whack-a-mole trying to fix typings on DefinitelyTyped to work in dom-less repos.
Edit: some DefinitelyTyped issues this causes:
- 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
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de microsoft/TypeScript-DOM-lib-generator
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
microsoft/TypeScript-DOM-lib-generator#2554 · 6 comentarios ·
-
lib.d.ts bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
lib.d.ts bug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 68/100
microsoft/TypeScript-DOM-lib-generator#2154 · 1 reacción ·
-
lib.d.ts bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
microsoft/TypeScript-DOM-lib-generator#2107 · 5 comentarios ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
microsoft/TypeScript-DOM-lib-generator#1675 · 2 comentarios · 1 reacción ·
Todos los issues de microsoft/TypeScript-DOM-lib-generator
Issues similares
-
S: triage
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
-
fix(errors): EHOSTUNREACH from a happy-eyeballs connect is reported as a resolver error (STAMP-80) Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 90/100
snapshot-labs/stamp#666 ·
-
fix(api): prevent leaderboard SSE heartbeat from starting after disconnect during initial load Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
GauravKarakoti/SecureFlow#1070 · 1 comentario ·
-
feature:Languages/Translations good first issue ready Web
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
digitalfabrik/integreat-app#4394 ·