@types/mdx 2.0.5 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. mdx/README.md +1 -1
  2. mdx/package.json +2 -2
  3. mdx/types.d.ts +55 -8
mdx/README.md CHANGED
@@ -8,7 +8,7 @@ This package contains type definitions for mdx (https://github.com/mdx-js/mdx).
8
8
  Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/mdx.
9
9
 
10
10
  ### Additional Details
11
- * Last updated: Thu, 27 Apr 2023 10:02:45 GMT
11
+ * Last updated: Tue, 08 Aug 2023 13:02:51 GMT
12
12
  * Dependencies: none
13
13
  * Global values: none
14
14
 
mdx/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@types/mdx",
3
- "version": "2.0.5",
3
+ "version": "2.0.6",
4
4
  "description": "TypeScript definitions for mdx",
5
5
  "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/mdx",
6
6
  "license": "MIT",
@@ -30,6 +30,6 @@
30
30
  },
31
31
  "scripts": {},
32
32
  "dependencies": {},
33
- "typesPublisherContentHash": "08c145be25e7de13f9272bcde2549ae1b24ce6e7063f0cf6f7364234e09e9f20",
33
+ "typesPublisherContentHash": "0291678e8f54ab65f2d0f2edd6347724cd789d8ccb70e1bdcfa9696a59b9ef92",
34
34
  "typeScriptVersion": "4.3"
35
35
  }
mdx/types.d.ts CHANGED
@@ -1,12 +1,56 @@
1
1
  // Internal helper types
2
2
 
3
- // tslint:disable-next-line: strict-export-declare-modifiers
4
- type FunctionComponent<Props> = (props: Props) => JSX.Element | null;
5
- // tslint:disable-next-line: strict-export-declare-modifiers
6
- type ClassComponent<Props> = new (props: Props) => JSX.ElementClass;
7
- // tslint:disable-next-line: strict-export-declare-modifiers
8
- type Component<Props> = FunctionComponent<Props> | ClassComponent<Props> | keyof JSX.IntrinsicElements;
9
- // tslint:disable-next-line: strict-export-declare-modifiers
3
+ /**
4
+ * This is the global JSX.ElementType if it’s defined, otherwise never.
5
+ */
6
+ // @ts-ignore JSX runtimes may optionally define JSX.ElementType. The MDX types need to work regardless whether this is
7
+ // defined or not.
8
+ type ElementType = any extends JSX.ElementType ? never : JSX.ElementType;
9
+
10
+ /**
11
+ * This matches any function component types that ar part of `ElementType`.
12
+ */
13
+ type FunctionElementType = Extract<ElementType, (props: Record<string, any>) => any>;
14
+
15
+ /**
16
+ * This matches any class component types that ar part of `ElementType`.
17
+ */
18
+ type ClassElementType = Extract<ElementType, new (props: Record<string, any>) => any>;
19
+
20
+ /**
21
+ * A valid JSX string component.
22
+ */
23
+ type StringComponent = Extract<keyof JSX.IntrinsicElements, ElementType extends never ? string : ElementType>;
24
+
25
+ /**
26
+ * A valid JSX function component.
27
+ */
28
+ type FunctionComponent<Props> = ElementType extends never
29
+ ? // If JSX.ElementType isn’t defined, the valid return type is JSX.Element
30
+ (props: Props) => JSX.Element | null
31
+ : FunctionElementType extends never
32
+ ? // If JSX.ElementType is defined, but doesn’t allow function components, function components are disallowed.
33
+ never
34
+ : // If JSX.ElementType allows function components, its return value determines what is a valid.
35
+ (props: Props) => ReturnType<FunctionElementType>;
36
+
37
+ /**
38
+ * A valid JSX class component.
39
+ */
40
+ type ClassComponent<Props> = ElementType extends never
41
+ ? // If JSX.ElementType isn’t defined, the valid return type is a constructor that returns JSX.ElementClass
42
+ new (props: Props) => JSX.ElementClass
43
+ : ClassElementType extends never
44
+ ? // If JSX.ElementType is defined, but doesn’t allow constructors, function components are disallowed.
45
+ never
46
+ : // If JSX.ElementType allows class components, its return value determines what is a valid.
47
+ new (props: Props) => InstanceType<ClassElementType>;
48
+
49
+ /**
50
+ * Any allowed JSX component.
51
+ */
52
+ type Component<Props> = FunctionComponent<Props> | ClassComponent<Props> | StringComponent;
53
+
10
54
  interface NestedMDXComponents {
11
55
  [key: string]: NestedMDXComponents | Component<any>;
12
56
  }
@@ -19,7 +63,7 @@ interface NestedMDXComponents {
19
63
  * The key is the name of the element to override. The value is the component to render instead.
20
64
  */
21
65
  export type MDXComponents = NestedMDXComponents & {
22
- [Key in keyof JSX.IntrinsicElements]?: Component<JSX.IntrinsicElements[Key]>;
66
+ [Key in StringComponent]?: Component<JSX.IntrinsicElements[Key]>;
23
67
  } & {
24
68
  /**
25
69
  * If a wrapper component is defined, the MDX content will be wrapped inside of it.
@@ -62,3 +106,6 @@ export interface MDXModule {
62
106
  */
63
107
  default: MDXContent;
64
108
  }
109
+
110
+ // This marks the file as a module, meaning not all types are implicitly exported.
111
+ export {};