= P & { as?: T }; + +export type PolymorphicPropsWithoutRef
= Merge<
+ React.ComponentPropsWithoutRef
+>;
+
+export type PolymorphicPropsWithRef = Merge<
+ React.ComponentPropsWithRef
+>;
+
+// TODO:
+// - PolymorphicFunctionComponent
+// - PolymorphicVoidFunctionComponent (requires @types/react >=16.9.48)
+
+type PolymorphicExoticComponent<
+ P = {},
+ T extends React.ElementType = React.ElementType
+> = Merge<
+ React.ExoticComponent ,
+ {
+ /**
+ * **NOTE**: Exotic components are not callable.
+ */
+ ,
+ ): React.ReactElement | null;
+ }
+>;
+
+export type PolymorphicForwardRefExoticComponent<
+ P,
+ T extends React.ElementType
+> = Merge<
+ React.ForwardRefExoticComponent ,
+ PolymorphicExoticComponent
+>;
+
+export type PolymorphicMemoExoticComponent<
+ P,
+ T extends React.ElementType
+> = Merge<
+ React.MemoExoticComponent
+>;
+
+export type PolymorphicLazyExoticComponent<
+ P,
+ T extends React.ElementType
+> = Merge<
+ React.LazyExoticComponent
+>;
diff --git a/package-lock.json b/package-lock.json
new file mode 100644
index 0000000..9190df4
--- /dev/null
+++ b/package-lock.json
@@ -0,0 +1,42 @@
+{
+ "name": "react-polymorphic-types",
+ "version": "1.0.0",
+ "lockfileVersion": 1,
+ "requires": true,
+ "dependencies": {
+ "@types/prop-types": {
+ "version": "15.7.3",
+ "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.3.tgz",
+ "integrity": "sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw==",
+ "dev": true
+ },
+ "@types/react": {
+ "version": "17.0.0",
+ "resolved": "https://registry.npmjs.org/@types/react/-/react-17.0.0.tgz",
+ "integrity": "sha512-aj/L7RIMsRlWML3YB6KZiXB3fV2t41+5RBGYF8z+tAKU43Px8C3cYUZsDvf1/+Bm4FK21QWBrDutu8ZJ/70qOw==",
+ "dev": true,
+ "requires": {
+ "@types/prop-types": "*",
+ "csstype": "^3.0.2"
+ }
+ },
+ "csstype": {
+ "version": "3.0.5",
+ "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.0.5.tgz",
+ "integrity": "sha512-uVDi8LpBUKQj6sdxNaTetL6FpeCqTjOvAQuQUa/qAqq8oOd4ivkbhgnqayl0dnPal8Tb/yB1tF+gOvCBiicaiQ==",
+ "dev": true
+ },
+ "prettier": {
+ "version": "2.2.1",
+ "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.2.1.tgz",
+ "integrity": "sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==",
+ "dev": true
+ },
+ "typescript": {
+ "version": "4.1.3",
+ "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.3.tgz",
+ "integrity": "sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg==",
+ "dev": true
+ }
+ }
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..c455ceb
--- /dev/null
+++ b/package.json
@@ -0,0 +1,41 @@
+{
+ "name": "react-polymorphic-types",
+ "version": "1.0.0",
+ "description": "Zero-runtime polymorphic component definitions for React",
+ "keywords": [
+ "react",
+ "polymorphism",
+ "as-prop",
+ "typescript"
+ ],
+ "homepage": "https://github.com/kripod/react-polymorphic-types#readme",
+ "bugs": {
+ "url": "https://github.com/kripod/react-polymorphic-types/issues"
+ },
+ "repository": "github:kripod/react-polymorphic-types",
+ "license": "MIT",
+ "author": "Kristóf Poduszló