web-components icon indicating copy to clipboard operation
web-components copied to clipboard

TypeScript: investigate converting tests that use private API

Open web-padawan opened this issue 4 years ago • 1 comments

It's quite simple to convert our tests to use TypeScript, as demonstrated here.

const { esbuildPlugin } = require('@web/dev-server-esbuild');

module.exports = {
  nodeResolve: true,
  plugins: [
    esbuildPlugin({ ts: true })
  ]
};

However, we are using protected and private APIs in many tests, which becomes problematic when converting them to TS. One possible option would be to create shared helpers for all of those, so we only have @ts-expect-error there.

web-padawan avatar May 07 '21 13:05 web-padawan

To use private API in the tests, we can either use

Casting to any

(grid as any)._isExpanded('foo');

Or defining a test type for the Private API:

type GridElementWithInternalAPI<ItemType> = Grid<ItemType> & {
  _isExpanded(item: ItemType): boolean;
};

return (grid as GridElementWithInternalAPI<string>)._isExpanded('foo');

tomivirkki avatar Dec 01 '23 09:12 tomivirkki