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

ResolveJsonModule String Literal Type TypeCheck failure #31920

Closed
sanderhahn opened this issue Jun 15, 2019 · 2 comments
Closed

ResolveJsonModule String Literal Type TypeCheck failure #31920

sanderhahn opened this issue Jun 15, 2019 · 2 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@sanderhahn
Copy link

TypeScript Version: 3.4.0-dev.201xxxxx

Search Terms:

resolveJsonModule String Literal Type TS2322

Code

// @resolveJsonModule: true
type Gender = "male" | "female";
const correct: { gender: Gender } = { gender: "male" }; // okay

import * as input from "./example.json"; // example.json contains {"gender": "male"}
const incorrect: { gender: Gender } = input; // Type 'string' is not assignable to type 'Gender'

Expected behavior:
Correctly compiles

Actual behavior:

example.ts:7:7 - error TS2322: Type '{ "gender": string; }' is not assignable to type '{ gender: Gender; }'.
  Types of property 'gender' are incompatible.
    Type 'string' is not assignable to type 'Gender'.
@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jun 26, 2019
@RyanCavanaugh
Copy link
Member

JSON files don't get literal types; see #26552

@sanderhahn
Copy link
Author

Ah okay, i understand!
Thanks for all the great work on TypeScript :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

2 participants