microsoft / microsoft/TypeScript
Inconsistencies in ESM-style imports of accessibility-modified properties from CJS-exported classes
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 132
Descripción
Acknowledgement
- I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.
Comment
Search terms
import AND class AND (protected OR private OR modifier)
Description
Given the following CJS module:
class X {
public static a = 1;
protected static b = 2;
private static c = 3;
}
export = X;
then the behaviour of the static properties when using ESM-style imports is variable. For example,
import { a, b, c } from "module.cjs";
is permitted, but
import * as m from "module.cjs";
const { a, b, c } = m;
is not (m is an alias to the CJS export X, so this counts as a class property access and is subject to accessibility checks).
Protected and private class properties are also offered by tsserver for Intellisense suggestions when using ESM-style imports, but are obviously hidden when offering properties of the "namespace" object created by import * (since it's just an alias to the exported class), and do not appear in its keyof.
(The same would also apply if the CJS export were an instance of a class with accessibility-modified prototype properties, but exporting a class constructor is the more likely scenario encountered in the wild.)
Exposing intended-to-be-hidden properties in this way is almost always going to have been unintentional, and the alternative behaviour is fairly straightforward: add accessibility checks for NamedImports elements when the import target is a CJS export.
Guía de contribución
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.
Línea de trabajo
Comienza con el ejemplo de clase CJS-exportada del issue y sigue cómo TypeScript gestiona NamedImports frente a un import-star namespace cuando el destino es una clase exportada. Reproduce la diferencia de accesibilidad y verifica después que los named imports también imponen comprobaciones de accesibilidad sin exponer propiedades protegidas o privadas.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- compilers
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 38/100