Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ts] Consolidate UI Typescript types, update generate script #207137

Open
clintandrewhall opened this issue Jan 17, 2025 · 1 comment
Open

[ts] Consolidate UI Typescript types, update generate script #207137

clintandrewhall opened this issue Jan 17, 2025 · 1 comment
Labels
enhancement New value added to drive a business result Team:Operations Team label for Operations Team

Comments

@clintandrewhall
Copy link
Contributor

clintandrewhall commented Jan 17, 2025

I've tried resolving this myself, but run into some frustrating issues. Hoping someone from @elastic/kibana-operations has some knowledge I don't.

There are a number of important Typescript declarations that need to be added to the tsconfig.json of a package to have it function properly, at least from a UX perspective:

  • @emotion/react/types/css-prop: Enables the css= property on React nodes. Without it, you get a TS error.
  • @kbn/ambient-ui-types: Enables importing png, svg, html and others. Without it, you get a TS error.
  • kibana/typings/emotion.d.ts: Types the parameter passed to css= to be equivalent to the EUI theme. [1]. Without it, consumers do not know they have access to the EUI theme, (and call a hook manually).

Inclusion of these types should (probably) be in any package that includes React code. Ideally, these would all be consolidated into a single TS type package or reference. Unfortunately, tsconfig.json arrays cannot be merged with extending, so even though they're included in tsconfig.base.json, and tsconfig that extends it and includes the types property, has to copy them wholesale.

I tried combining these in various ways-- in the same file, combining references, etc-- but can't get them all to work at the same time.

A test case would be something like:

import React from 'react';
import { css } from '@emotion/react';

import mdx from './some_file.mdx';
import pngPath from './some_image.png';

export const Component = () => (
  <div css={({euiTheme}) => (
    css`
      background-color: ${euiTheme.color.backgroundBasePlain};
    `)}>
     <code>{mdx}</code>
     <img src={pngPath />
  </div>
);

Some folks have added some of the references, others have included ../../../[etc]/typings/** as well. It's all very haphazard, and requires past knowledge. Ideally, we'd have a single tsconfig.json reference, and have it automatically included with the template for --web packages created by scripts/generate.

As a result, everything would be enabled properly, and we wouldn't have gaps in knowledge or packages.

@clintandrewhall clintandrewhall added enhancement New value added to drive a business result Team:Operations Team label for Operations Team labels Jan 17, 2025
@clintandrewhall
Copy link
Contributor Author

The easiest option here would be to create a package for typings/emotion.d.ts, add it to tsconfig.base.json, and delete the types portion of all package tsconfig.json files that don't deviate from the base file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New value added to drive a business result Team:Operations Team label for Operations Team
Projects
None yet
Development

No branches or pull requests

1 participant