question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow extending types referenced through interfaces

See original GitHub issue

Suggestion

Allow things like the following:

interface I extends HTMLElementTagNameMap['abbr'] {}

Currently, the following error message is given: “An interface can only extend an identifier/qualified-name with optional type arguments.” Which I don’t even understand.

I believe it requires no further clarification or justification, but please let me know if that is the case…

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:13
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
corehcommented, Jul 9, 2019

As long as you assign the type a name it works, and it does the proper check already:

interface Bar {}
interface Baz {}

// This doesn't work
interface Foo extends (Bar & Baz) {}

// This works
type _tmp = Bar & Baz;
interface Foo extends _tmp {};

// This fails with a meaningful error message:
// > An interface can only extend an object type or intersection of object types with statically known members. ts(2312)
type _tmp2 = Bar | Baz;
interface Foo extends _tmp2 {};

So IMO we should definitely support the anonymous/expression version of this for orthogonality/consistency

3reactions
RyanCavanaughcommented, Jun 13, 2019

In principle it’s doable - we can detect when the resolved entity is a legal extends target

Read more comments on GitHub >

github_iconTop Results From Across the Web

Extending object-like types with interfaces in TypeScript
Extending multiple interfaces refers to the concept of composition where the interface is designed to extend attributes it needs. It differs ...
Read more >
Possible to extend types in Typescript? - Stack Overflow
UPDATE for TypeScript 2.2, it's now possible to have an interface that extends object-like type, if the type satisfies some restrictions:
Read more >
Handbook - Interfaces - TypeScript
In TypeScript, interfaces fill the role of naming these types, and are a powerful way of defining contracts within your code as well...
Read more >
Using an Interface as a Type (The Java™ Tutorials > Learning ...
When you define a new interface, you are defining a new reference data type. You can use interface names anywhere you can use...
Read more >
Object Interfaces - Manual - PHP
Interfaces can be extended like classes using the extends operator. Note: The class implementing the interface must declare all methods in the interface...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found