-
-
Notifications
You must be signed in to change notification settings - Fork 603
Open
Labels
bugSomething isn't workingSomething isn't workingopenapi-tsRelevant to the openapi-typescript libraryRelevant to the openapi-typescript library
Description
openapi-typescript version
7.9.1
Node.js version
24.5.0
OS + version
NixOS 25.11
Description
I'm trying to load a request body from a json file. When I do that i get type errors on the assignment to a variable that is annotated with the corresponding type. If I manually construct the json inline typescript is totally happy. The error I get is Type 'string' is not assignable to type '"bar"'. I can try to provide more information if it will help. But I can't share my actual types/api so it will require a little bit of work.
<script lang="ts">
import type { components } from "./mySchema";
// Typescript is happy here
let x: components['schema']['MyType'] = { foo: "bar" }
// Typescript gives me type errors here
import data from './example.json';
let x: components['schema']['MyType'] = data
</script>example.json:
{ "foo": "bar" }Reproduction
If needed I can try to make a minimal reproduction. But I first wanted to hear if this is expected/trivial to solve.
Expected result
Expecting no type errors
Required
- My OpenAPI schema is valid and passes the Redocly validator (
npx @redocly/cli@latest lint)
Extra
- I’m willing to open a PR (see CONTRIBUTING.md)
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingopenapi-tsRelevant to the openapi-typescript libraryRelevant to the openapi-typescript library