Not able to set id on a component when using typescript with cypress

I’ve been trying to test my lightning application(typescript) with cypress. According to the documentation adding the below code should set the id on the HTML element.

get id() {
  return 'BrowsePage'

Error -
Property ‘id’ in type ‘Item’ is not assignable to the same property in base type ‘Component<ItemTemplateSpec, TypeConfig>’.
Type ‘string’ is not assignable to type ‘number’.
‘id’ is defined as a property in class ‘Component<ItemTemplateSpec, TypeConfig>’, but is overridden here in ‘Item’ as an accessor.

id is already defined in the Lightning Element class.

Please suggest any alternative way to add id to HTML elements.

1 Like

Looks like a bug with the typescript info. @frank will look into a fix

ah Wonderful I’m having the same issue!

@jps @Ben Indeed this was a miss! Thanks for letting us know. I’ve created an Issue + PR for this. It will likely land in our next monthly release. In the mean time, you may add something like this above it to ignore the error:

// @ts-expect-error This version of Lightning's TS definitions do not support overriding this getter with a string.

When you finally upgrade to the the fixed Lightning version, TypeScript will let you know, via errors, that you can remove those directive comments.

1 Like

Thank you so much @frank for the quick fix!

1 Like