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.

Assigning js.undefined to a type alias to js.UndefOr does not compile

See original GitHub issue
import scala.scalajs.js.|
import scala.scalajs.js
type Foo = Int | String
type FooOpt = js.UndefOr[Foo]
val foo: js.UndefOr[Foo] = js.undefined // Works
val foo2: FooOpt = js.undefined // Doesn't work: "Expected `Nothing | Unit`,  got `Int | String | Unit`"

Unclear if we can do anything about this, but opening this so we have a centralized discussion point.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
sjrdcommented, Aug 5, 2020

I believe it would be worth creating a reproduction independent of Scala.js, and report it to Scala/JVM instead. AFAICT there is no reason for the implicit resolution to fail in the original scenario. Fixing it there upstream has the highest chance not to break zillions of other things.

0reactions
frobinetcommented, Jan 19, 2021

Sure. I haven’t had the bandwidth to reproduce and submit this issue to Scala/JVM, but closing it here is legitimate. I’ll reference this issue if I ever get to reporting to Scala/JVM.

Read more comments on GitHub >

github_iconTop Results From Across the Web

js.UndefOr as alias for union broke Scala 2.12.0 #3024 - GitHub
The reason appears to be that the typer is happy with the subtyping relationship between undefined of type UndefOr[Nothing] and UndefOr[String] ...
Read more >
Refine to type alias in union - Stack Overflow
The problem with this is that type refinement must operate at both compile-time and runtime, but runtime will have no awareness of the...
Read more >
How To Use Type Aliases in TypeScript - DigitalOcean
In this tutorial, you will refactor code that uses string literals to include aliases. You will be able to use and understand TypeScript...
Read more >
Type Aliases vs Interfaces in TypeScript - DEV Community ‍ ‍
This article will discuss the similarities and differences between them, and the best use cases for each. Let's dive in! Type aliases. A...
Read more >
SIP public review: explicit Nulls - Scala Improvement Process
Hi Scala Community! This thread is the SIP Committee's request for comments on a proposal to make reference types non-nullable by default ...
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