Don't typealias Month (and others)
See original GitHub issueI suggest to not typealias anything in a multiplatform date/time library.
- It mixes platform-provided API into the library’s API which causes confusion and is platform-dependent.
- It doesn’t allow for adding a companion and thus “static” functionality - not even through extensions.
For example:
I had code in the back-end that used Month.of(someInt)
. The code was relatively simple and there were no JVM-specific imports. So I’ve moved it to a shared multiplatform dependency and was surprised that Month.of()
was no longer available. Month.<autocomplete>
didn’t provide me with any useful alternative.
After Cmd-clicking on Month
I’ve learned that it is merely a typealias on JVM. It took a while to figure out that there’s an additional Month(Int)
function in kotlinx-datetime that I should’ve used instead. Scenarios like that can easily lead to confusion and inconsistency.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:5
Top Results From Across the Web
firebase - Problems with typealias swift - Stack Overflow
Hey i have a code that uses a typealias so that it will be able to send an error code to the user...
Read more >Mailman 3 Explicit Type Aliases - Typing-sig - python.org
Proposal (with explicit aliases): ``` from typing import List, TypeAlias ... At this point we don't know whether T is a type or...
Read more >PEP 604 unions don't work with generic type aliases #12211
Anyway, to the concrete suggestion of having to explicitly list the type vars generic type aliases are generic over — I think it's...
Read more >How to use Typealias in Swift | Continued Learning #19
In this quick video, we will learn a simple implementation of Typealias. This lesser known declaration is used to create an alias (...
Read more >Swift - How to use typealias | Swift 5.2, Xcode 11 - YouTube
Head to https://squarespace.com/seanallen to save 10% off your first purchase of a website or domain using code SEANALLEN.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@september669 the whole library requires coreLibraryDesugaring to be enabled enabling the use of java.time on previous API levels.
With Kotlin 1.5 it became super annoying and really needs to be changed.