#Trouble Serializing Images - Type Error Issue

60 messages · Page 1 of 1 (latest)

distant sphinxBOT
hallow viperBOT
#

Original message from @grim forge - Moved from #general message

ember rivet
#

What's the type before you declare one with as

grim forge
#

SerializedLexicalNode

#

I feel like it should be SerializedUploadNode but that doesn't exist yet

ember rivet
#

whats the rest of the code look like

#

im looking at other exampels on github

grim forge
ember rivet
#

where they do like

#
type SerializedLexicalNode =
  | SerializedLexicalNodeText
  | SerializedLexicalNodeLink
  | SerializedLexicalNodeLinebreak
  | SerializedLexicalNodeList
  | SerializedLexicalNodeListitem
  | SerializedLexicalNodeHeading
grim forge
#

it seems no one has done img

#

so maybe i shouldn't be serializing img?

ember rivet
#

Hmm, good question

grim forge
#

if i search img in the types file, it doesn't exist either. so maybe i should just manually write out the type.

ember rivet
#

Maybe because it's not a root node

#

and cant have children?

grim forge
#

it makes sense to serialise because then it's in the correct order and you can move the img's around

#

dunno, but the code works fine

#

it just has a type error

ember rivet
#

Hmm

grim forge
#

so in that way i think i've done things right. i should just manually write the types, which is fine but i'm not used to doing that as a lot of payload types are prewritten

ember rivet
#

@willow summit Does this sound right?

#

(They made this)

grim forge
#

thank you!

#

I'm so close to leaving it as any, but I'm too much of a perfectionist lol

ember rivet
#

Lmao I feel that

#

We have like 2-3 anys in our work repo

#

and I'm convinced they are unsolveable so I have an ignore rule on them for lint specifically lol

grim forge
#

I am relatively new to typescript as well, so kind of want to learn

#

hahaha

ember rivet
#

Unsolveable as in, out of my control without more trickery

#

What you could do is

#

Make a new type that is like

grim forge
#

yeah i get you. if i have to write 50 lines of code to solve this, i'm not sure if there's much point. unless it errors somehow, but it's a pretty simple thing

ember rivet
#

blah: SerializedNode & {otherProp: string}

#

so that you're not using any

#

but specifying an extended type

grim forge
#

yeah i might do that. i tried but it said error converting type, so i went downstairs and bit into chocolate

#

ill try that again and see if it works

ember rivet
#

Valid result

#

lmao

#

Yeah lmk, most of the team is still waking up (im not on the team)

#

but maybe someone with more insight will pop in

grim forge
#

thank you for the help! I'll see how it goes

#
interface MyNewType extends SerializedLexicalNode {
    value: {
        url: string;
    };
}
#

that solves it

ember rivet
#

Yasss

#

If it were me, I'd be cool with that

#

TBH

grim forge
#

thank you! i am happy now

ember rivet
#

If you're going to be confused with types anywhere in the project

grim forge
#

yeah i think it just wasn't in the code by default, so im happy

ember rivet
#

I'd guess itd be with slate or lexical

#

so not uncommon

#

Nice resolution1

grim forge
#

thank you so much! haha. that was easy with the extends feature

ember rivet
#

anytime