Added typedef for @reach/alert (#35509)

This commit is contained in:
Harry Hedger 2019-05-16 07:55:00 -07:00 committed by Nathan Shively-Sanders
parent 56395c2fc1
commit 60d1e6c75b
4 changed files with 67 additions and 0 deletions

13
types/reach__alert/index.d.ts vendored Normal file
View File

@ -0,0 +1,13 @@
// Type definitions for @reach/alert 0.1
// Project: https://github.com/reach/reach-ui
// Definitions by: Harry Hedger <https://github.com/hedgerh>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import * as React from 'react';
export type AlertProps = {
type?: "assertive" | "polite";
} & React.HTMLProps<HTMLDivElement>;
export const Alert: React.FC<AlertProps>;

View File

@ -0,0 +1,25 @@
import { Alert } from '@reach/alert';
import * as React from "react";
import { render } from "react-dom";
render(<Alert />, document.getElementById('app'));
// should handle both types
render(<Alert type="assertive" />, document.getElementById('app'));
render(<Alert type="polite" />, document.getElementById('app'));
// Should take div props and spread them down to div tag
render(<Alert onDoubleClick={() => {}} />, document.getElementById('app'));
render(
<Alert type="assertive">This is a standard alert.</Alert>,
document.getElementById('app')
);
// Should explode on a bad type
// $ExpectError
render(<Alert type="foo" />, document.getElementById('app'));
// Should throw on a bad prop
// $ExpectError
render(<Alert badProp />, document.getElementById('app'));

View File

@ -0,0 +1,28 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"paths": {
"@reach/alert": ["reach__alert"]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react"
},
"files": [
"index.d.ts",
"reach__alert-tests.tsx"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }