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.

Suggestion: Allow interface to extend conditional type

See original GitHub issue

An interface cannot currently extend a conditional type. See: (playground link)

type Test<T> = T extends {} ? { test: T } : {}

// Ok: type with selected condition
interface I extends Test<number> { }

// "Error: An interface may only extend a class or another interface."
interface J<T> extends Test<T> { }

// Ok: type without condition
type Test2<T> = { test: T }
interface K<T> extends Test2<T> { }

This example exhibits one of these problems:

  • J<T> should be allowed to extend Test<T>, to make it more complete and allow conditional type things in interfaces. –OR
  • The error message should be made more clear, because interfaces can obviously extend types as you can see above.

Issue Analytics

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

github_iconTop GitHub Comments

m-hendersoncommented, Sep 28, 2019

@RyanCavanaugh you mentioned the only thing we can do is update the error message; @mhegazy do you agree with that? if so, what does the diagnostics message need to say so that it is accurate than the current diagnostics message?

infogulchcommented, May 3, 2018

Hmm. If all the possible types the condition could evaluate to are object types, and an interface extends it, the interface is still an object type even if it’s conditional, no? I.e. even though it’s conditional, it’s still guaranteed to resolve to some object type.

If that’s not a strong enough guarantee because of compiler/typesystem/implementation reasons, I won’t argue it any farther. Thank you for your explanations!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Conditional types in TypeScript - Artsy Engineering
This extends keyword is the heart of a conditional type. A extends B means precisely that any value of type A can safely...
Read more >
Conditionally getting the type of interface property in typescript
The conditional type you're going for seems to be a red flag for me. ... The conditional you want is <key> extends keyof...
Read more >
Documentation - Conditional Types - TypeScript
Create types which act like if statements in the type system.
Read more >
Advanced TypeScript: The Power and Limitations of ... - Medium
The infer keyword can go inside of a conditional type to the right of the extends keyword. Using infer is asking TypeScript to...
Read more >
Code completion | IntelliJ IDEA Documentation - JetBrains
Expand a string at caret to an existing word · Type the initial string and do one of the following: Press Alt+/ or...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found