#vitest errors

7 messages · Page 1 of 1 (latest)

tidal peak
#

hello, i wanted to test my code with this tool AND...

it seems that it has issues with types...
code:

import { describe, expect, it } from 'vitest';
import { basketballParser } from '../parsers/basketballParser';

describe('Basketball Parser',()=>{
    it('should output properly parsed data for Basketball',()=>{
       const basketObject = basketballParser({
            sport: 'basketball', 
            participant1: 'GKS Tychy',
            participant2: 'GKS Katowice',
            score: [
                ['9:7', '2:1'],
                ['5:3', '9:9']
            ],
        })
    })
  });

the errors:
Type '"basketball"' is not assignable to type 'sportsEnum'.
Property 'score' is missing in type 'string[][]' but required in type 'Score'.

types he is talking about:

export declare interface Score {
    score: string | string[][]
}

export declare interface EventInterface {
    sport: sportsEnum,
    participant1: string,
    participant2: string,
    score: Score
}

and the enum:

export enum sportsEnum {
    volleyball = 'volleyball',
    basketball = 'basketball',
    handball = 'handball',
    tennis = 'tennis',
    soccer = 'soccer',
}

I literary pass proper data to the function, but he is complaining for some reason, any ideas why?

#

sport field fixed - i needed to use exact enum eg:

            sport: sportsEnum.basketball, 
#

but score is something im struggling with

fair hazel
#

@tidal peak Yeah, the score property is defined as Score type which is an object with a score property.

#

So according to the types, as written, this should be:

{
  sport: sportsEnum.basketball,
  participant1: "GKS Tychy",
  participant2: "GKS Katowice",
  score: {
    score: [
      ["9:7", "2:1"],
      ["5:3", "9:9"],
    ],
  },
};
tidal peak
#

ty so much 😄

then i will just remove score type (im not using it anywhere else) and its just simple tulpe anyways 😄

#

!resolved