diff options
author | 2022-07-18 11:45:50 -0400 | |
---|---|---|
committer | 2022-07-18 11:45:50 -0400 | |
commit | 8eba6d9d977920bdb0830cc219e636236433b2fd (patch) | |
tree | e096a6360bed7f994b1dbfa2b77d66236cc17a25 | |
parent | b282cdb21f3bdfabb237fd479df701f4b87b7db3 (diff) | |
download | astro-8eba6d9d977920bdb0830cc219e636236433b2fd.tar.gz astro-8eba6d9d977920bdb0830cc219e636236433b2fd.tar.zst astro-8eba6d9d977920bdb0830cc219e636236433b2fd.zip |
Fix expected types for Element in our JSX definitions (#3958)
* Fix expected types for Element in our JSX definitions
* Add changeset
Diffstat (limited to '')
-rw-r--r-- | .changeset/nice-toes-cough.md | 5 | ||||
-rw-r--r-- | packages/astro/astro-jsx.d.ts | 24 | ||||
-rw-r--r-- | packages/astro/src/@types/astro.ts | 1 |
3 files changed, 17 insertions, 13 deletions
diff --git a/.changeset/nice-toes-cough.md b/.changeset/nice-toes-cough.md new file mode 100644 index 000000000..d4ca78fcb --- /dev/null +++ b/.changeset/nice-toes-cough.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix JSX definitions being too strict as to what an element is, which lead to type issues in certain cases (Markdown imports, JSX components etc) diff --git a/packages/astro/astro-jsx.d.ts b/packages/astro/astro-jsx.d.ts index 81d3d1f92..cf76e6e58 100644 --- a/packages/astro/astro-jsx.d.ts +++ b/packages/astro/astro-jsx.d.ts @@ -10,7 +10,6 @@ * @see https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/index.d.ts */ declare namespace astroHTML.JSX { - /* html jsx */ export type Child = Node | Node[] | string | number | boolean | null | undefined | unknown; export type Children = Child | Child[]; @@ -24,17 +23,18 @@ declare namespace astroHTML.JSX { children?: Children; } - type AstroBuiltinProps = import('astro').AstroBuiltinProps; - type AstroBuiltinAttributes = import('astro').AstroBuiltinAttributes; - type AstroDefineVarsAttribute = import('astro').AstroDefineVarsAttribute; - type AstroScriptAttributes = import('astro').AstroScriptAttributes & AstroDefineVarsAttribute; - type AstroStyleAttributes = import('astro').AstroStyleAttributes & AstroDefineVarsAttribute; - - // Certain Astro methods returns AstroComponent using AstroComponentFactory - // The language-server does not really like this because it expects Elements to - // all be compatible with HTMLElement so we'll add AstroComponentFactory as a valid element type - type AstroComponent = import('astro').AstroComponentFactory; - type Element = HTMLElement | AstroComponent; + type AstroBuiltinProps = import('./dist/types/@types/astro').AstroBuiltinProps; + type AstroBuiltinAttributes = import('./dist/types/@types/astro').AstroBuiltinAttributes; + type AstroDefineVarsAttribute = import('./dist/types/@types/astro').AstroDefineVarsAttribute; + type AstroScriptAttributes = import('./dist/types/@types/astro').AstroScriptAttributes & + AstroDefineVarsAttribute; + type AstroStyleAttributes = import('./dist/types/@types/astro').AstroStyleAttributes & + AstroDefineVarsAttribute; + + // This is an unfortunate use of `any`, but unfortunately we can't make a type that works for every framework + // without importing every single framework's types (which comes with its own set of problems). + // Using any isn't that bad here however as in Astro files the return type of a component isn't relevant in most cases + type Element = HTMLElement | any; interface DOMAttributes { children?: Children; diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 370d6a4c2..766ee0607 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -16,7 +16,6 @@ import type { AstroConfigSchema } from '../core/config'; import type { ViteConfigWithSSR } from '../core/create-vite'; import type { AstroComponentFactory, Metadata } from '../runtime/server'; export type { SSRManifest } from '../core/app/types'; -export type { AstroComponentFactory } from '../runtime/server'; export interface AstroBuiltinProps { 'client:load'?: boolean; |