import { expectType , TypeEqual } from "ts-expect" ; import { fieldsAuto , fieldsUnion , number } from "../" ; test ( "using different tags in JSON and in TypeScript" , ( ) => { const decoder = fieldsUnion ( "type" , { circle : fieldsAuto ( { tag : ( ) => "Circle" as const , radius : number , } ) , square : fieldsAuto ( { tag : ( ) => "Square" as const , size : number , } ) , } ) ; type InferredType = ReturnType < typeof decoder > ; type ExpectedType = { tag : "Circle" ; radius : number ; } | { tag : "Square" ; size : number ; } ; expectType < TypeEqual < InferredType , ExpectedType > > ( true ) ; expect ( decoder ( { type : "circle" , radius : 5 } ) ) . toMatchInlineSnapshot ( `
      Object {
        "radius": 5,
        "tag": "Circle",
      }
    ` ) ; } ) ;