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

JsonValue can receive type but not interface #815

Open
fregante opened this issue Feb 15, 2024 · 1 comment
Open

JsonValue can receive type but not interface #815

fregante opened this issue Feb 15, 2024 · 1 comment

Comments

@fregante
Copy link

fregante commented Feb 15, 2024

import {JsonValue} from "type-fest";

declare function identity(value: JsonValue): JsonValue;

interface InterfaceObject {
    origin: string;
}

const objectViaInterface: InterfaceObject = {
    origin: 'red'
};

identity(objectViaInterface);
// Argument of type 'InterfaceObject' is not assignable to parameter of type 'JsonValue'.
//   Type 'InterfaceObject' is not assignable to type 'JsonObject'.
//    Type 'InterfaceObject' is not assignable to type '{ [x: string]: JsonValue; }'.
//      Index signature for type 'string' is missing in type 'InterfaceObject'.(2345)

type TypeObject = {
    origin: string;
}

const objectViaType: TypeObject = {
    origin: 'red'
};

identity(objectViaType) // Fine

https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbwFIGcIDsBqBDANgVwFMBfOAMyghDgCIYBPMQgWjMJRhoG4AoHgE0IBjXNiiFy+dEJjAMcYIPSyGACgBueIgC44qDDgKEAlLv1YthXj2DLCUMtiESAknYdPCAeQBGAK2F4BB44ULhoYABzW10OKFtI3mI+IQwOcP9AzGBsNxh7R2ddPILPXwCZOABeRBCwiOj0XQBycX5mnmJrRUJlYDUITJls3PdCkz4GJjgAFUZvIfga4LDw+MbYmHj0RM6UtPhBipgRuaZdM4Xj6trVhpi4VsJ2zu6lFXpVI6ycy+MgA

Jsonify "fixes" the issue in some cases but it breaks in other

Generic issue for:

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
@fregante
Copy link
Author

In my case I'm using extends OmitIndexSignature<JsonValue> and that silenced the issue for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant