Skip to content
Discussion options

You must be logged in to vote

It's because your initial value doesn't match with your type.
This fixes it: https://tsplay.dev/NaM02N

import { atom } from 'jotai';

interface DisplayedSong {
  song: number;
  bookFirstIndex: number | undefined; // <- accept undefined
  bookLastIndex: number | undefined;
  currentReport?: any;
}

const displayedSongInfoAtom = atom<DisplayedSong>({
  song: 1, // <- here it's giving an error
  bookFirstIndex: undefined,
  bookLastIndex: undefined,
  currentReport: undefined,
});

interface MyObject {
  first: number;
  index: number;
}

const myObject = atom<MyObject>({ 
  first: 1, // <- here it isn't
  index: -1 
});

I agree the TS error message isn't very understandable, but I'm not su…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@biskyy
Comment options

Answer selected by biskyy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
2 participants