Fix expected types for Element in our JSX definitions (#3958)
* Fix expected types for Element in our JSX definitions * Add changeset
This commit is contained in:
parent
b282cdb21f
commit
8eba6d9d97
3 changed files with 16 additions and 12 deletions
5
.changeset/nice-toes-cough.md
Normal file
5
.changeset/nice-toes-cough.md
Normal file
|
@ -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)
|
22
packages/astro/astro-jsx.d.ts
vendored
22
packages/astro/astro-jsx.d.ts
vendored
|
@ -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;
|
||||
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;
|
||||
|
||||
// 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;
|
||||
// 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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue