Skip to content
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

override isn't required in ambient contexts with noImplicitOverride #60635

Closed
Andarist opened this issue Nov 28, 2024 · 2 comments
Closed

override isn't required in ambient contexts with noImplicitOverride #60635

Andarist opened this issue Nov 28, 2024 · 2 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@Andarist
Copy link
Contributor

πŸ”Ž Search Terms

override ambient type declaration class dts noImplicitOverride

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play/?noImplicitOverride=true&ts=5.8.0-dev.20241128&ssl=15&ssc=2&pln=1&pc=1#code/PTAEAEDsHsEkFsAOAbAlgY1QFwPIDcBTAJyNQBMCAuULIgVwIChGL1kBDIg0N9gZz6gAQv24BvRqFAAjapDrxpxANyMAvs1YcuPDgNAARYqkJlQBAB5YCkMoJF9xkmXIVKiqjSwK8dvfQ4EAEygYl5anNz+gkakpiGW1rb2oiESUtCEJOTcsqDyiirqjEA

πŸ’» Code

// @noImplicitOverride: true

declare class Base {
  b: number;
}

declare class Derived extends Base {
  b: number; // no error
}

declare class Base2 {}

declare class Derived2 extends Base2 {
  override b: number; // error
}

πŸ™ Actual behavior

A property in a derived class in ambient context doesn't have to have override modifier with noImplicitOverride. override is still checked when present though.

πŸ™‚ Expected behavior

It feels slightly inconsistent. I couldn't find any note about this in the docs and I had to look into the source code and dig up the PR that implemented override to check if it's a bug or not.

Additional information about the issue

I believe this works like that since noImplicitOverride was introduced in #39669 in 4.3: TS playground

@whzx5byb
Copy link

Seems like there was a decision:

- Should this apply to declaration files?
  - Argument for yes: correctness for the same reason
  - Argument for no: convenience, no need to mess with declaration emitter
  - If no: Declaration emitter will need to emit `override` modifier (same way `any` works) if one was not present explicitly
  - Decision: Not enforced

Originally posted by @RyanCavanaugh in #9034

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Dec 2, 2024
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants