`--experimentalDecorators`: decorated `abstract` property is emitted as a class field (regression in 7.0)
Los mantenedores suelen responder en 1 día
Ya se ha fusionado un pull request relacionado.
- #64982 de @1-DARK — fusionado
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Stack tecnológico
- typescript
- Área
- compilers
Línea de trabajo
Start by reading typeeraser.go around the decorated declare and abstract property handling, then follow visitPropertyDeclaration in legacydecorators.go to see why the preserved node emits a field. Compare with the visitPropertyDeclaration handling in ts.ts described in the issue. Done means the abstract property is erased while its legacy decorator call remains, matching the expected output; an open pull request is already linked.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
🔎 Search Terms
experimentalDecorators, abstract property, decorator, class field, useDefineForClassFields, typeeraser, legacy decorators
🕗 Version & Regression Information
- Regression from tsc 6.0.3, which erases the field.
- Reproduces in 7.0.2, 7.1.0-beta and 7.1.0-dev.20261026.1.
💻 Code
function dec(target: object, key: string) {
Object.defineProperty(target, key, { get: () => 'from prototype', configurable: true });
}
abstract class Base {
@dec abstract data: string;
}
class Sub extends Base {
declare data: string;
}
const s = new Sub();
console.log(Object.hasOwn(s, 'data'), s.data);
{ "compilerOptions": { "target": "es2022", "experimentalDecorators": true } }
🙁 Actual behavior
Base gets a data; field, so every instance has an own data: undefined that shadows whatever the decorator put on the prototype. Prints true undefined.
class Base {
data;
}
__decorate([
dec
], Base.prototype, "data", void 0);
🙂 Expected behavior
Same as tsc 6.0.3: the field is erased and only the __decorate call remains. Prints false from prototype.
class Base {
}
__decorate([
dec
], Base.prototype, "data", void 0);
Additional information about the issue
The field appears only when all three hold: experimentalDecorators, a decorator on the abstract property, and define semantics (useDefineForClassFields, the default at target ES2022 and later). emitDecoratorMetadata makes no difference. An undecorated abstract property and a decorated declare property are both still erased.
The likely cause is in typeeraser.go. For a decorated declare/abstract property under experimentalDecorators, it keeps the node so that LegacyDecoratorsTransformer can emit the __decorate call. But it rebuilds the node with VisitModifiers, which elides AbstractKeyword. visitPropertyDeclaration in legacydecorators.go then finds neither NodeFlagsAmbient nor ModifierFlagsAbstract and emits a field. declare escapes this because the node keeps NodeFlagsAmbient. Strada's visitPropertyDeclaration in ts.ts handles the same case by appending a declare modifier to the preserved node (concatenate(modifiers, factory.createModifiersFromModifierFlags(ModifierFlags.Ambient))).
We hit this in TypeORM entities: an abstract base declares a decorated abstract column, each subclass redeclares it with declare, and every entity instance gains an own data: undefined it doesn't have under tsc 6.
- Lenguaje dominante
- Go
- Estrellas
- 112k
- Forks
- 15.4k
- Merge medio
- 3 d 1 h
- PR fusionados (30 d)
- 136
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la 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.
Más de microsoft/TypeScript
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
microsoft/TypeScript#65290 ·
Los mantenedores suelen responder en 1 día
-
Native API: formatDiagnosticsWithColorAndContext drops related information without a file locationQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
microsoft/TypeScript#65087 ·
Los mantenedores suelen responder en 1 día
-
TS7 LSP: documentHighlight returns nothing when the file path contains '@'Quizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. AbiertoBug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
microsoft/TypeScript#64758 ·
Los mantenedores suelen responder en 1 día
-
Language server (tsc --lsp) exits with code 1 after `shutdown` and `exit`Posiblemente ocupada @rajnish-verma-22172 la tomó hace 13 días. AbiertoBug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
microsoft/TypeScript#64742 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Non-enum CLI options with multiple values separated by comma and space aren't whitespace trimmedPosiblemente ocupada @RyanCavanaugh la tomó hace 28 días. AbiertoBug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
microsoft/TypeScript#64618 · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de microsoft/TypeScript
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
riverqueue/river#1576 ·
Los mantenedores suelen responder en 1 día
-
NFS StorageProvider renders a missing nfsSubDir as "<no value>"Posiblemente ocupada @ldming la tomó hoy. Abiertokind/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
apecloud/kubeblocks#11067 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
emersion/go-msgauth#87 ·
-
CLI: `describe <ns>.<table>` reports "namespace does not exist" when only the table is missingPosiblemente ocupada @Shruthirdy la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
apache/iceberg-go#2423 ·
Los mantenedores suelen responder en 2 días
-
Add tests for CSV email parsingAbiertogood first issue help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
mafzalkalwardev/mailforge#21 ·