#Weird type issue with vitest

10 messages · Page 1 of 1 (latest)

proud dome
#

Visual Studio Code and typescript seemingly have issues when trying to use type information from my libary.
The class method i'm calling has id on the interface it returns but typescript is adamant that it doesn't and intelisense seems to think the method is returning the same class despite also telling me it's the correct interface

Test code:

import { assert, expect, test, describe } from 'vitest'
import { HCB }  from '../../src';

describe('Single Org ID tests', () => {
    const hcb = new HCB();
    test('GIVEN hq THEN returns correct org id', async () => {
        const org = await hcb.organization.singleOrganization({
            id: "hq"
        });
        expect(org.id).equals("org_a29uVj");
    })
});

The interface:
import type { HCB_User } from "./user";

export interface HCB_Organization {
    id: string;
    object: string;
    href: string;
    name: string;
    slug: string;
    category: "hackathon" | "high_school_hackathon" | "event" | "hack_club" | "nonprofit" | "robotics_team" | "hardware_grant" | "hack_club_hq";
    transparent: boolean;
    demo_mode: boolean;
    logo: string;
    public_message: string;
    balances: {
        balance_cents: number;
        fee_balance_cents: number;
        incoming_balance_cents: number;
    };
    created_at: string;
    users: HCB_User[];
}
deft scaffold
proud dome
#
    public async singleOrganization(data: { id: string, expand?: string }) {
        /**
         * Get a single organization by ID or slug
         * @returns {Promise<HCB_Organization>} Organization object
         * @param data {object} Object containing the ID or slug of the organization to fetch and an optional expand parameter to expand objects (should be a string seperated by commas)
         * @async
         */
        let url = `organizations/${data.id}`
        url += await queryFormer(data);
        const res = await fetchWrapper<HCB_Organization>(url);
        return res;
    }
deft scaffold
#

so it's quite hard to fix issue where there is no errors because it's kind of a guess and try but I am guessing it's a problem from typescript's dumb way of inferring types

#

typescript is so dumb at inferring types that I recommend manually adding return types to your methods

#

sometimes typescript creates two interfaces without the same properties as it tried to infer stuff

proud dome
#

How do I do that again lol

deft scaffold
#

you add : thetype

something(): string
proud dome
#

Ohh

#

My class and interface were called the same thing...