-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Description
I'm using typescript 3.7.2 & useDefineClassFields flag.
I think the field with declare modifier should not emit to js code.
but, the field with declare modifier emitting to js code (Object.defineProperty).
Is it normal?
The typescript 3.7 document explain like this. Am I misunderstanding?
"To help mitigate the second issue, you can either add an explicit initializer or add a declare modifier to indicate that a property should have no emit."
TypeScript Version: 3.7.2
Code
interface Animal { animalStuff: any }
interface Dog extends Animal { dogStuff: any }
class AnimalHouse {
resident: Animal;
constructor(animal: Animal) {
this.resident = animal;
}
}
class DogHouse extends AnimalHouse {
declare resident: Dog;
// ^^^^^^^
// 'resident' now has a 'declare' modifier,
// and won't produce any output code.
constructor(dog: Dog) {
super(dog);
}
}Expected behavior:
"use strict";
class AnimalHouse {
constructor(animal) {
Object.defineProperty(this, "resident", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this.resident = animal;
}
}
class DogHouse extends AnimalHouse {
// ^^^^^^^
// 'resident' now has a 'declare' modifier,
// and won't produce any output code.
constructor(dog) {
super(dog);
}
}Actual behavior:
"use strict";
class AnimalHouse {
constructor(animal) {
Object.defineProperty(this, "resident", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this.resident = animal;
}
}
class DogHouse extends AnimalHouse {
// ^^^^^^^
// 'resident' now has a 'declare' modifier,
// and won't produce any output code.
constructor(dog) {
super(dog);
Object.defineProperty(this, "resident", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels