Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested structure without index signature is not assignable to Jsonifiable #778

Open
bleistift-zwei opened this issue Dec 3, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@bleistift-zwei
Copy link

bleistift-zwei commented Dec 3, 2023

Consider this simple nested data structure:

interface Inner {
  foo: string
}

interface Outer {
  bar: Inner
}

A value of type Outer can be losslessly converted to and from JSON. However, assigning it to a variable of type Jsonifiable won’t compile with TS 5.5.2 and type-fest@4.20.1 Playground link:

declare const outer: Outer
let jsonifiable: Jsonifiable = outer
//  ^ Type 'Outer' is not assignable to type 'Jsonifiable'.
//      Type 'Outer' is not assignable to type '{ [x: string]: Jsonifiable | undefined; }'.
//        Index signature for type 'string' is missing in type 'Outer'.(2322)

I believe the assignment should be valid.

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • The funding will be given to active contributors.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@sindresorhus
Copy link
Owner

// @itsjohncs

@fregante fregante added the bug Something isn't working label Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants