Recoil icon indicating copy to clipboard operation
Recoil copied to clipboard

[TypeScript] Type {} does not satisfy the constraint 'SerializableParam'

Open apetti1920 opened this issue 4 years ago • 5 comments

Not so much of a bug as a work around in case anyone runs into a similar problem. When typing any param parameter (eg atomFamily) the error:

Type {} does not satisfy the constraint 'SerializableParam'

will appear and can be overcome by unioning the two types together as such:

type paramType = SerializableParam & {
  id: number
}

apetti1920 avatar Jul 09 '20 04:07 apetti1920

@csantos42 - is this a TypeScript typing issue?

drarmstr avatar Jul 09 '20 18:07 drarmstr

Oh yes sorry should have prefaced with that

apetti1920 avatar Jul 12 '20 02:07 apetti1920

@csantos42 - Is this somewhat related to this?

drarmstr avatar Jul 28 '20 17:07 drarmstr

Hope this is useful Related commentary SerializableParam @csantos42

If I want to provide a parameter to selectorFamily

interface MySelectorParam {
    a: string
    b: string
}

For selectorFamily I get an error in the type signature when:

const theThing = selectorFamily<ReturnType, MySelectorParam>({...

Screen Shot 2020-09-14 at 2 27 06 pm

but not when:

const theThing = selectorFamily<ReturnType, { a: string; b: string }>({...

Screen Shot 2020-09-14 at 2 28 48 pm

bentron2000 avatar Sep 14 '20 04:09 bentron2000

Change from interface to type worked for me

kaynetpc avatar Jul 13 '22 03:07 kaynetpc

Change from interface to type worked for me

That's one weird solution, but as long as it works. 🥇

KonkretneKosteczki avatar Oct 06 '22 07:10 KonkretneKosteczki