Skip to content

Typescript: Observer prop type is not extracting #102

Description

@quolpr

Giving:

type Props = { note: NoteModel; database: Database; noteId: string };

const NotePageComponent: React.FC<Props> = ({ note }) => {
  const database = useDatabase();
  const history = useHistory();

  return (
    <>
      {note && (
        <Calendar
          onChange={async (date) => {
            if (isArray(date)) return;

            const note = await getOrCreateDailyNote(database, dayjs(date));

            history.replace(`/notes/${note.id}`);
          }}
          value={dayjs(note.title, 'D MMM YYYY').toDate()}
        />
      )}
      <Note noteId={note.id} />
    </>
  );
};

type InputProps = ObservableifyProps<Props, 'note'>;

const NotePageEnch = withDatabase<InputProps>(
  withObservables(['noteId'], ({ database, noteId }: InputProps) => {
    const note = database.collections
      .get<NoteModel>(HarikaNotesTableName.NOTES)
      .findAndObserve(noteId);

    return {
      note,
    };
})(/* error here ->>> */NotePageComponent)
);

I get such typescript error:

TS2345: Argument of type 'FC<Props>' is not assignable to parameter of type 'ComponentType<Matching<ExtractedObservables<{ note: Observable<Note>; }>, Props>>'.
  Type 'FunctionComponent<Props>' is not assignable to type 'FunctionComponent<Matching<ExtractedObservables<{ note: Observable<Note>; }>, Props>>'.
    Types of property 'propTypes' are incompatible.
      Type 'WeakValidationMap<Props> | undefined' is not assignable to type 'WeakValidationMap<Matching<ExtractedObservables<{ note: Observable<Note>; }>, Props>> | undefined'.
        Type 'WeakValidationMap<Props>' is not assignable to type 'WeakValidationMap<Matching<ExtractedObservables<{ note: Observable<Note>; }>, Props>>'.
          Types of property 'note' are incompatible.
            Type 'Validator<Note> | undefined' is not assignable to type 'Validator<Observable<Note>> | undefined'.
              Type 'Validator<Note>' is not assignable to type 'Validator<Observable<Note>>'.
                Type 'Note' is not assignable to type 'Observable<Note>'.
Version: typescript 4.0.5

Typescript version 4.0.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions