Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Comments on Why does the types returned by 'valueOf()' are incompatible with the type `Partial<Temporal.PlainDate>`?

Post

Why does the types returned by 'valueOf()' are incompatible with the type Partial<Temporal.PlainDate>? [closed]

+0
−4

Closed as unclear by Karl Knechtel‭ on Jun 7, 2025 at 21:23

This question cannot be answered in its current form, because critical information is missing.

This question was closed; new answers can no longer be added. Users with the Vote on Holds ability may vote to reopen this question if it has been improved or closed incorrectly.

This code:

type A = Partial<Temporal.PlainDate>;
const a: A = { day: 1, month: 1, year: 2025 }

yields this error:

Type '{ day: number; month: number; year: number; }' is not assignable to type 'Partial<PlainDate>'.
  The types returned by 'valueOf()' are incompatible between these types.

      The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?

I expect the type check to pass. In my understanding, Partial<X> is a type with all properties of X set to optional, so a should have no error. If this is the intended restriction, then how can I create a Partial<Temporal.PlainDate> instance?

const a = new Temporal.PlainDate(2025, 1, 1) works. I just wonder why using Partial doesn't work here. Reading Temporal.PlainDate.prototype.valueOf() doesn't help.

History

2 comment threads

Why this is unclear (3 comments)
I wonder if using `new Temporal.PlainDate(year, month, day)` instead of that object literal works. (2 comments)
Why this is unclear
Karl Knechtel‭ wrote over 1 year ago

What do you expect to happen when the code runs? For example, do you expect that const a: A = { day: 1, month: 1, year: 2025 } should cause a to become an instance of the Partial<Temporal.PlainDate> class (constructing it from the values in the object)? Or do you just expect the type check to pass? Where the error message says "Type '{ day: number; month: number; year: number; }' is not assignable to type 'Partial'.", was this unclear to you? Or rather - why do you expect that it should be assignable? What should that assignment mean?

Aside from this - are you actually asking about a design decision to disallow the assignment? (If so, are you asking about how Typescript works, or are you asking about how the assignment works?) Or are you actually asking a how-to question, about how to create the Partial<Temporal.PlainDate> instance you want?

Ooker‭ wrote over 1 year ago

Thanks for taking time to help me clear. I expect the type check to pass. In my understanding, Partial<X> is a type with all properties of X set to optional, so a should have no error. If this is the intended restriction, then how can I create a Partial<Temporal.PlainDate> instance?

Karl Knechtel‭ wrote over 1 year ago · edited over 1 year ago

Did you try assigning it to a Temporal.PlainDate typed variable first? Does that work?