-
Notifications
You must be signed in to change notification settings - Fork 12.8k
override
modifier should able to be used with declare
modifier
#51515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
|
I'm a little disagree with this interpretation. Even if you disagree with Given what |
Yes, that’s what If you want something to not be emitted, use |
You see, I already have multiple layered inherited classes, a very complex structure. Like in the examples, most subclasses don't have a constructor. They are just decorated differently. I don't really care about the emit/no-emit of the properties. And now, with this This doesn't work. People choose TypeScript for its readability and maintainability. It's a shame that TypeScript is willing to drop both for |
Another approach. Remove this error if I don't know what's happening around I don't think you will get a good adoption of Maybe Interview some real-world users. |
If your issue is Also, please tone down the language and hostility if you don't want the TS devs to lock your issue. |
@fatcerberus Apologies If my words are too offensive. I'm not very good at English after all. I just wanted to express my feeling on this issue and the direction it is developing. Now I believe you have acknowledged my frustration. I hope the user frustration still means something to TS devs. Maybe I'll start a new issue and rephrase all about this after further discussion. It's not about the new ES Class define behaviour, not on their part. This is exactly a TypeScript issue. According to your own reply here, you are well aware of no matter what TS do, the eventual behaviour will change because of the underlying runtime. class DogHouse extends AnimalHouse {
@Prop({
default: {
animalStuff: 'food',
dogStuff: 'dog food',
}
})
override resident!: Dog;
} At least it should have an option to disable this error. FYI the decorator is working as expected. I authored those decorators. It's using the |
I've put it in another way, hopefully it can convenience you more. |
Please consider this case. import type { Model, ModelView, Prop } from 'myORMLib';
@Model
class SomeModel {
@Prop({ type: 'uint16' })
prop1!: number;
// ... propN: type;
@Prop({ maxLength: 256 })
prop15!: string;
}
// make all properties readonly
// So ugly, but works! (ignore the 2612 error here)
@ModelView
class ReadonlySomeModel extends SomeModel {
@Prop({ readonly: true })
readonly prop1!: SomeModel["prop1"];
// ... propN: SomeModel["propN"];
@Prop({ readonly: true })
readonly prop15!: SomeModel["prop15"];
} I have to write And now imagine how cool it would be if decorators works with // make all properties readonly
// 🦄🌈 beauty and shine 🌈🦄
@ModelView
class ReadonlySomeModel extends SomeModel {
@Prop({ readonly: true })
declare readonly prop1;
// ... declare readonly propN;
@Prop({ readonly: true })
declare readonly prop15;
} |
Suggestion
🔍 Search Terms
useDefineForClassFields
override declare
'override' modifier cannot be used with 'declare' modifier. ts(1243)
Property 'a' will overwrite the base property in 'Cls'. If this is intentional, add an initializer. Otherwise, add a 'declare' modifier or remove the redundant declaration.(2612)
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
When declaring class fields:
The
override
modifier should be able to be used withdeclare
modifier.Have
!
work in the place ofdeclare
OR:Remove this error if
!
oroverride
is specifically given: Property 'a' will overwrite the base property in 'Cls'. If this is intentional, add an initializer. Otherwise, add a 'declare' modifier or remove the redundant declaration.(2612)📃 Motivating Example
Given a decorator
Prop()
that somehow declares some metadata on the class field,that would later be used in some other technical components like Database ORMs or Validators, etc.
Consider this example, before
useDefineForClassFields
set totrue
:Note that the
DogHouse
is defined quite straightforward and expected in a general sense.Now after
useDefineForClassFields
set totrue
, the current way of specifying theDogHouse
becomes:It doesn't look too bad, but things can get more complicated:
Now it sucks.
The consistency and readability from using
override
is completely screwed up bydeclare
.At least the
override
should be allowed to be used withdeclare
to make it suck a little less:The best case however, is to have
!
work in the place ofdeclare
:💻 Use Cases
As example suggested.
The code readability degradation from
declare
is unacceptable.I am using typescript with
useDefineForClassFields
set tooff
now.Please consider my suggestion..
The text was updated successfully, but these errors were encountered: