language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

Wrong classes interpretation

Open NathanAP opened this issue 7 months ago • 5 comments

Vue - Official extension or vue-tsc version

2.0.26

VSCode version

1.90.2

Vue version

3.4.31

TypeScript version

5.5.3

System Info

tbh not sure if this is relevant because I'm in Gitpod.

Steps to reproduce

Hey guys! Sorry if this is not the right place to post my situation.

I have the following code where it used to work some time ago (TS 5.3.3 for sure):

export type VisualizationItem = {
    index: number
    title: string
    value: string
    object: Database
}
const databaseList = ref<VisualizationItem[]>([])
const selectedItem = ref<string[]>([])

const selectedDatabase = computed(() => {
    if (!selectedItem.value.length) return null

    const databaseFound = databaseList.value.find(
        (v) => v.value === selectedItem.value[0]
    )
    if (!databaseFound) return null

    return databaseFound
})

But when I do something like...

function test(object: Database) { 
   console.log(object.id)
}

if (selectedDatabase.value)
   test(selectedDatabase.value.object) // this throws ts-plugin(2345)

...2345 error is being thrown, which doesn't make sense because my selectedDatabase should be a VisualizationItem. Looking forward in this, I discovered that when I hover over my computed or ref variables, the following is being shown:

image

It seems that vs code can no longer identify that my object part is a Database and it shows me as a simple object, which throws the following:

image

Edit: I tried const databaseList: Ref<VisualizationItem[]> = ref([]) and this works fine.

What is expected?

No errors should be thrown because everything is typed.

What is actually happening?

TS 2345 is thrown and it says that my variable has the wrong type.

Link to minimal reproduction

No response

Any additional comments?

No response

NathanAP avatar Jul 05 '24 13:07 NathanAP