Skip to content

Commit

Permalink
Attempt to update types
Browse files Browse the repository at this point in the history
  • Loading branch information
davenquinn committed Oct 23, 2024
1 parent 9c98be6 commit 59adac7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 28 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"@macrostrat/revision-info-webpack": "^1.0.0",
"@macrostrat/storybook": "workspace:*",
"@mdx-js/rollup": "^2.3.0",
"@types/esprima": "^4",
"@types/underscore": "^1",
"@typescript-eslint/eslint-plugin": "^6.3.0",
"@typescript-eslint/parser": "^6.3.0",
Expand Down
67 changes: 40 additions & 27 deletions src/declaration.d.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,57 @@
// declaration.d.ts

import type { Hyper } from "@macrostrat/hyper";
import type { Component, ReactNode, ReactElement } from "react";

type Children = ReactNode | ReactNode[];

declare module "@macrostrat/hyper" {
interface Hyper {
// Function with one or two arguments
(componentOrTag: Component, children?: Children): ReactNode;

// Function with three arguments, with one being props
<P = {}>(
componentOrTag: Component<P>,
props: P,
children?: Children
): ReactNode;

// Function with one list of elements -> React fragment
(children?: ReactNode[]): ReactNode[];
}
}

import { Hyper } from "@macrostrat/hyper";

// Favicon etc.
declare module "*.png" {
const value: string;
export default value;
}

// Union of hyper and record
type StyledHyper = Hyper & Record<string, string>;
// Get the hyper function from our custom module

type Classes = { readonly [key: string]: string };

type StyledHyper = Classes & Hyper;

// Style modules
declare module "*.module.styl" {
const classes: { readonly [key: string]: string };
export default StyledHyper;
}

// Override declarations for sass module
declare module "*.module.sass" {
const classes: Classes;
export default StyledHyper;
}

// Override declarations for sass module
declare module "*.module.scss" {
import styles from "./main.module.sass";
const classes: { [key: string]: string };
export default classes;
export default StyledHyper;
}

declare module "*.styl" {
Expand All @@ -27,26 +63,3 @@ declare module "*.sass" {
const content: string;
export default content;
}

// Override declarations for sass module
declare module "*.module.sass" {
const classes: { [key: string]: string };
export default classes;
}

type Children = ReactNode | ReactNode[];

declare module "@macrostrat/hyper" {
export interface Hyper {
// Function with one or two arguments
(componentOrTag: Component, children?: Children): Children;
// Function with three arguments, with one being props
<P = {}>(
componentOrTag: Component<P>,
props: P,
children?: ReactElement
): Children;
// Function with one list of elements -> React fragment
(children?: ReactNode[]): ReactElement;
}
}

0 comments on commit 59adac7

Please sign in to comment.