Repository navigation
Add Date to ContentValue - #708
NullVoxPopuli wants to merge 5 commits into
Conversation
{ toString(): string } to ContentValue
|
I'm not sure we should type either API unless they are fixed to be reactive, see https://github.com/glimmerjs/glimmer-vm-issues/issues/5 I think this because without these things being reactive, types may steer folks to greater usage and a lot of silent, difficult to debug bugs around accidental memoization. |
|
Anything that inherits from |
|
Philosophically, I would categorize this as |
|
I'll revert back to just Date then.. |
{ toString(): string } to ContentValueDate to ContentValue
|
changed pushed! 🎉 |
|
I am 🤷🏼♂️ on adding Date specifically, but I would like to point out that:
No I don't think that's what any of us would like to see or is seriously proposing. What you would need to do is to cast it to a string explicitly, just like you would when calling any function in TypeScript that specifically requires a string. So really you just have to do the equivalent of What is slightly unfortunate is that there is no convenient method call syntax in the template (which is a separate thing we can and probably should add). It's also a bit of a dance to grab the global const { String } = globalThis;
<template>
{{String ...}}
</template>or... (doesn't work today but I think we agreed it should) <template>
{{globalThis.String ...}}
</template>Not that much of a dance, but it is a dance. However, you probably really want to have a dedicated helper for this in your app anyway, specifically: function String(value: unknown): string {
let string = String(value);
assert("not like that!", string !== "[object Object]");
// and any other checks you may want
return string;
}..in which case it's just another helper you would import just like any others. And it does auto-track. I would also say that, of all the things we can choose to cover here, the utility of having Same goes for a few of the other things that have a non-trivial I think it is important to highlight we aren't really talking about a missing capability here. You can definitely render the Ultimately though, I suppose it's more a matter of taste/philosophy/consistency and I'd defer to @dfreeman for that. Notably, TypeScript isn't terribly consistent:
|
I'm inclined to agree. While the default
100%, exactly.
In the context of this discussion, I think it's worth noting that
I'm not the keeper of the keys on this project at this point, but to the extent my opinion still holds weight I agree that |
per discussion, toString won't happen
Anything with
{ toString(): string }is renderable, including Date, boolean, etc.We should reflect the reality of what is renderable in the
ContentValuetype.It already has
{ toHTML(): string }support, which is great, but{ toString(): string }should cover most other cases.Old Description:
Dates are renderable.
otherwise, you gotta cast your value to something like
x as Date & { toHtml(): string }which is silly, and relies on secret knowledge of how SafeString works.