From 60d1e6c75ba1361869a944d7c4b859dd68ad1cf3 Mon Sep 17 00:00:00 2001 From: Harry Hedger Date: Thu, 16 May 2019 07:55:00 -0700 Subject: [PATCH] Added typedef for @reach/alert (#35509) --- types/reach__alert/index.d.ts | 13 +++++++++++ types/reach__alert/reach__alert-tests.tsx | 25 ++++++++++++++++++++ types/reach__alert/tsconfig.json | 28 +++++++++++++++++++++++ types/reach__alert/tslint.json | 1 + 4 files changed, 67 insertions(+) create mode 100644 types/reach__alert/index.d.ts create mode 100644 types/reach__alert/reach__alert-tests.tsx create mode 100644 types/reach__alert/tsconfig.json create mode 100644 types/reach__alert/tslint.json diff --git a/types/reach__alert/index.d.ts b/types/reach__alert/index.d.ts new file mode 100644 index 0000000000..1d77c752f9 --- /dev/null +++ b/types/reach__alert/index.d.ts @@ -0,0 +1,13 @@ +// Type definitions for @reach/alert 0.1 +// Project: https://github.com/reach/reach-ui +// Definitions by: Harry Hedger +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +import * as React from 'react'; + +export type AlertProps = { + type?: "assertive" | "polite"; +} & React.HTMLProps; + +export const Alert: React.FC; diff --git a/types/reach__alert/reach__alert-tests.tsx b/types/reach__alert/reach__alert-tests.tsx new file mode 100644 index 0000000000..4b25a99808 --- /dev/null +++ b/types/reach__alert/reach__alert-tests.tsx @@ -0,0 +1,25 @@ +import { Alert } from '@reach/alert'; + +import * as React from "react"; +import { render } from "react-dom"; + +render(, document.getElementById('app')); + +// should handle both types +render(, document.getElementById('app')); +render(, document.getElementById('app')); + +// Should take div props and spread them down to div tag +render( {}} />, document.getElementById('app')); +render( + This is a standard alert., + document.getElementById('app') +); + +// Should explode on a bad type +// $ExpectError +render(, document.getElementById('app')); + +// Should throw on a bad prop +// $ExpectError +render(, document.getElementById('app')); diff --git a/types/reach__alert/tsconfig.json b/types/reach__alert/tsconfig.json new file mode 100644 index 0000000000..aa3176a327 --- /dev/null +++ b/types/reach__alert/tsconfig.json @@ -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" + ] +} diff --git a/types/reach__alert/tslint.json b/types/reach__alert/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/reach__alert/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }