sindresorhus/type-fest

Jsonify makes Record<string, any> disappear

Open

#667 aberto em 24 de ago. de 2023

Ver no GitHub
 (7 comments) (0 reactions) (0 assignees)TypeScript (471 forks)batch import
enhancementhelp wanted

Métricas do repositório

Stars
 (12.328 stars)
Métricas de merge de PR
 (Mesclagem média 3d 5h) (11 fundiu PRs em 30d)

Description

Here's a TS Playground:

import type { Jsonify } from "type-fest";

type Data = Jsonify<{
  payload: Record<string, any>;
}>;

declare const d: Data;
console.log(d.payload) // <-- Property 'payload' does not exist on type 'JsonifyObject<{}>'.

This feels like a bug to me. It's causing an issue for me in the upcoming version of Remix: https://github.com/remix-run/remix/issues/7246

My current workaround is to change the type to unknown instead of any (https://github.com/edmundhung/conform/pull/272 which will hopefully be merged soon). I think is the proper thing to do, but sometimes that's hard because you may not control the type. I think it's more correct to keep the record around on the type.

Guia do colaborador