oy
oy copied to clipboard
Typescript Definition Files
Hi would be great to have .d.ts files for this project. Would you happen to already have that and be able to share?
Thanks, -Jeff
There isn't a TypeScript definition file made for Oy yet. It will likely take me some time to read up on creating and verifying one (and can't promise a date), so I'm happy to accept pull requests in the meantime. I'll leave this bug open for tracking purposes.
Something like the below is a pretty rough but effective enough beginning, for anyone looking at types for Oy.
it lets you import { Table } from 'oy-vey' as well as
import oy from 'oy-vey'
const { Table, renderTemplate} = Oy
but it doesn't let you import { renderTemplate } from'oy-vey, as allowing this has resulted in runtime exceptions for me, so I presume that's how the package is structured.
The types:
declare module 'oy-vey' {
export const Table: React.DetailedHTMLFactory<Oy.OyTableElements, HTMLTableElement>;
export const TBody: React.DetailedHTMLFactory<Oy.OyTBodyElements, HTMLTableSectionElement>;
export const TR: React.DetailedHTMLFactory<Oy.OyTRElements, HTMLTableRowElement>;
export const TD: React.DetailedHTMLFactory<Oy.OyTDElements, HTMLTableDataCellElement>;
export const Img: React.DetailedHTMLFactory<Oy.OyImgElements, HTMLImageElement>;
export const A: React.DetailedHTMLFactory<Oy.OyAElements, HTMLAnchorElement>;
const renderTemplate: (jsx: JSX.Element, opts: Oy.RenderOpts) => string;
export default { Table, TBody, TR, TD, Img, A, renderTemplate };
}
declare namespace Oy {
interface OyElement {
width?: number | string;
height?: number | string;
align?: string;
background?: string;
bgColor?: string;
border?: number | string;
vAlign?: string;
}
interface OyTBodyElements extends React.HTMLAttributes<HTMLTableSectionElement>, OyElement {}
interface OyTableElements extends React.TableHTMLAttributes<HTMLTableElement>, OyElement {}
interface OyTRElements extends React.HTMLAttributes<HTMLTableRowElement>, OyElement {}
interface OyTDElements extends React.TdHTMLAttributes<HTMLTableDataCellElement>, OyElement {}
interface OyImgElements extends React.ImgHTMLAttributes<HTMLImageElement>, OyElement {}
interface OyAElements extends React.AnchorHTMLAttributes<HTMLAnchorElement>, OyElement {}
export type RenderOpts = {
title: string;
previewText: string;
headCSS?: string;
bgColor?: string;
lang?: string;
dir?: string;
};
}
---EDIT--- I've actually improved everything I didn't like about the types since posting them, so I'll probably make a PR to DefinitelyTyped with these in the near future.
@sampsonjoliver you should make the PR to this repo instead, if @revivek will accept it. Always better to bundle the types with the project when possible.
Whoops, totally forgot to push my types and make the PR on DefinitelTyped in the first place.
@ianjsikes I agree, bundled types are aces. The types are totally comprehensive though, so I'd advocate giving a thorough checking-over to make sure nothing's missing, before introducing strict-type checking errors to user's projects.
Anyhoo, here's a PR @revivek https://github.com/revivek/oy/pull/82