Skip to content
Permalink
Browse files

feat: first pass of typescript types for everything (#3411)

Welp, that took longer than I was expecting!

I think I've got a reasonable set of prop types for each module, but i got a bit tired of detailed checking towards the end.

I'm not sure whether the polymorphic `as` behaviour actually works correctly - although in theory the types I've got there should handle it.

Because of the generated types for the final component props, the error messages can be a bit wordy - but they do seem to also include the important information as well.

I've added dtslint into the build, but unfortunately this only checks the types against the `simple.test.tsx` file, it doesn't check the types against the actual implementation in any way.

Another mild annoyance is that although i've matched up the component filenames, the types don't work for the individual component files because of the `lib` vs `src` vs `es` part of the build process. In theory the files could be duplicated during the build for the exported code if this is desired.
  • Loading branch information
glenjamin authored and jquense committed Jan 14, 2019
1 parent 3779b3d commit 2079b2292afb835d036fcceef47e8938c4a8d86a
Showing with 1,956 additions and 1,960 deletions.
  1. +6 −2 package.json
  2. +1 −1 src/Badge.js
  3. +1 −0 types/.gitignore
  4. +0 −21 types/LICENSE
  5. +2 −31 types/README.md
  6. +0 −19 types/components/Accordion.d.ts
  7. +36 −13 types/components/Alert.d.ts
  8. +16 −7 types/components/Badge.d.ts
  9. +14 −8 types/components/Breadcrumb.d.ts
  10. +13 −9 types/components/BreadcrumbItem.d.ts
  11. +33 −13 types/components/Button.d.ts
  12. +14 −12 types/components/ButtonGroup.d.ts
  13. +12 −12 types/components/ButtonToolbar.d.ts
  14. +86 −0 types/components/Card.d.ts
  15. +9 −0 types/components/CardColumns.d.ts
  16. +9 −0 types/components/CardDeck.d.ts
  17. +9 −0 types/components/CardGroup.d.ts
  18. +13 −0 types/components/CardImg.d.ts
  19. +30 −26 types/components/Carousel.d.ts
  20. +7 −7 types/components/CarouselCaption.d.ts
  21. +5 −13 types/components/CarouselItem.d.ts
  22. +0 −13 types/components/Checkbox.d.ts
  23. +0 −13 types/components/Clearfix.d.ts
  24. +12 −0 types/components/CloseButton.d.ts
  25. +34 −26 types/components/Col.d.ts
  26. +18 −12 types/components/Collapse.d.ts
  27. +10 −8 types/components/Container.d.ts
  28. +0 −11 types/components/ControlLabel.d.ts
  29. +32 −25 types/components/Dropdown.d.ts
  30. +19 −15 types/components/DropdownButton.d.ts
  31. +15 −40 types/components/DropdownItem.d.ts
  32. +16 −13 types/components/DropdownMenu.d.ts
  33. +14 −14 types/components/DropdownToggle.d.ts
  34. +12 −11 types/components/Fade.d.ts
  35. +14 −0 types/components/Feedback.d.ts
  36. +15 −0 types/components/Figure.d.ts
  37. +9 −0 types/components/FigureCaption.d.ts
  38. +9 −0 types/components/FigureImage.d.ts
  39. +29 −9 types/components/Form.d.ts
  40. +29 −0 types/components/FormCheck.d.ts
  41. +19 −0 types/components/FormCheckInput.d.ts
  42. +15 −0 types/components/FormCheckLabel.d.ts
  43. +23 −16 types/components/FormControl.d.ts
  44. +0 −7 types/components/FormControlFeedback.d.ts
  45. +0 −10 types/components/FormControlStatic.d.ts
  46. +12 −11 types/components/FormGroup.d.ts
  47. +14 −0 types/components/FormLabel.d.ts
  48. +14 −0 types/components/FormText.d.ts
  49. +0 −12 types/components/Glyphicon.d.ts
  50. +0 −9 types/components/HelpBlock.d.ts
  51. +11 −9 types/components/Image.d.ts
  52. +31 −13 types/components/InputGroup.d.ts
  53. +0 −7 types/components/InputGroupAddon.d.ts
  54. +0 −7 types/components/InputGroupButton.d.ts
  55. +10 −6 types/components/Jumbotron.d.ts
  56. +0 −11 types/components/Label.d.ts
  57. +17 −9 types/components/ListGroup.d.ts
  58. +22 −13 types/components/ListGroupItem.d.ts
  59. +12 −19 types/components/Media.d.ts
  60. +0 −9 types/components/MediaBody.d.ts
  61. +0 −9 types/components/MediaHeading.d.ts
  62. +0 −9 types/components/MediaLeft.d.ts
  63. +0 −7 types/components/MediaList.d.ts
  64. +0 −9 types/components/MediaListItem.d.ts
  65. +0 −9 types/components/MediaRight.d.ts
  66. +0 −19 types/components/MenuItem.d.ts
  67. +38 −38 types/components/Modal.d.ts
  68. +7 −8 types/components/ModalBody.d.ts
  69. +9 −13 types/components/ModalDialog.d.ts
  70. +7 −7 types/components/ModalFooter.d.ts
  71. +12 −9 types/components/ModalHeader.d.ts
  72. +7 −7 types/components/ModalTitle.d.ts
  73. +26 −21 types/components/Nav.d.ts
  74. +20 −14 types/components/NavDropdown.d.ts
  75. +10 −24 types/components/NavItem.d.ts
  76. +20 −0 types/components/NavLink.d.ts
  77. +27 −52 types/components/Navbar.d.ts
  78. +10 −4 types/components/NavbarBrand.d.ts
  79. +7 −5 types/components/NavbarCollapse.d.ts
  80. +0 −7 types/components/NavbarHeader.d.ts
  81. +10 −6 types/components/NavbarToggle.d.ts
  82. +34 −16 types/components/Overlay.d.ts
  83. +18 −24 types/components/OverlayTrigger.d.ts
  84. +0 −7 types/components/PageHeader.d.ts
  85. +23 −7 types/components/PageItem.d.ts
  86. +0 −13 types/components/Pager.d.ts
  87. +0 −15 types/components/PagerItem.d.ts
  88. +16 −19 types/components/Pagination.d.ts
  89. +0 −10 types/components/PaginationEllipsis.d.ts
  90. +0 −10 types/components/PaginationFirst.d.ts
  91. +0 −11 types/components/PaginationItem.d.ts
  92. +0 −10 types/components/PaginationLast.d.ts
  93. +0 −10 types/components/PaginationNext.d.ts
  94. +0 −10 types/components/PaginationPrev.d.ts
  95. +0 −28 types/components/Panel.d.ts
  96. +0 −11 types/components/PanelBody.d.ts
  97. +0 −16 types/components/PanelCollapse.d.ts
  98. +0 −10 types/components/PanelFooter.d.ts
  99. +0 −15 types/components/PanelGroup.d.ts
  100. +0 −11 types/components/PanelHeading.d.ts
  101. +0 −12 types/components/PanelTitle.d.ts
  102. +0 −10 types/components/PanelToggle.d.ts
  103. +13 −15 types/components/Popover.d.ts
  104. +15 −17 types/components/ProgressBar.d.ts
  105. +0 −14 types/components/Radio.d.ts
  106. +12 −8 types/components/ResponsiveEmbed.d.ts
  107. +11 −6 types/components/Row.d.ts
  108. +15 −10 types/components/SafeAnchor.d.ts
  109. +25 −13 types/components/SplitButton.d.ts
  110. +0 −8 types/components/SplitToggle.d.ts
  111. +21 −19 types/components/Tab.d.ts
  112. +15 −8 types/components/TabContainer.d.ts
  113. +7 −10 types/components/TabContent.d.ts
  114. +16 −13 types/components/TabPane.d.ts
  115. +13 −12 types/components/Table.d.ts
  116. +19 −17 types/components/Tabs.d.ts
  117. +9 −0 types/components/ThemeProvider.d.ts
  118. +0 −11 types/components/Thumbnail.d.ts
  119. +20 −10 types/components/ToggleButton.d.ts
  120. +26 −33 types/components/ToggleButtonGroup.d.ts
  121. +12 −14 types/components/Tooltip.d.ts
  122. +0 −11 types/components/Well.d.ts
  123. +45 −0 types/components/helpers.d.ts
  124. +0 −382 types/components/index.d.ts
  125. +0 −2 types/components/utils/PropTypes.d.ts
  126. +0 −32 types/components/utils/StyleConfig.d.ts
  127. +0 −18 types/components/utils/bootstrapUtils.d.ts
  128. +0 −1 types/components/utils/capitalize.d.ts
  129. +0 −1 types/components/utils/createChainedFunction.d.ts
  130. +0 −3 types/components/utils/deprecationWarning.d.ts
  131. +0 −4 types/components/utils/index.d.ts
  132. +0 −1 types/components/utils/splitComponentProps.d.ts
  133. +68 −28 types/index.d.ts
  134. +0 −106 types/package.json
  135. +331 −0 types/simple.test.tsx
  136. +21 −0 types/tsconfig.json
  137. +23 −0 types/tslint.json
  138. +1 −1 www/src/examples/ResponsiveEmbed.js
  139. +2 −3 www/src/pages/utilities/responsive-embed.js
  140. +112 −5 yarn.lock
@@ -23,11 +23,12 @@
"release": "rollout",
"prepublishOnly": "npm run build",
"tdd": "karma start",
"test": "npm run lint && npm run test-browser && npm run test-node",
"test": "npm run lint && npm run dtslint && npm run test-browser && npm run test-node",
"test-browser": "cross-env NODE_ENV=test karma start --single-run",
"test-node": "cross-env NODE_ENV=test-server mocha --require @babel/register test/server/*Spec.js",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook"
"build-storybook": "build-storybook",
"dtslint": "dtslint types"
},
"lint-staged": {
"*.js": [
@@ -69,6 +70,7 @@
"@babel/preset-react": "^7.0.0",
"@babel/register": "^7.0.0",
"@storybook/react": "^3.4.8",
"@types/react": "^16.7.13",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"babel-loader": "^8.0.4",
@@ -82,6 +84,7 @@
"colors": "^1.3.3",
"create-react-class": "^15.6.3",
"cross-env": "^5.2.0",
"dtslint": "^0.4.1",
"enzyme": "^3.8.0",
"enzyme-adapter-react-16": "^1.7.1",
"eslint": "^5.10.0",
@@ -116,6 +119,7 @@
"release-script": "^1.0.2",
"sinon": "^7.2.2",
"sinon-chai": "^3.3.0",
"typescript": "^3.2.2",
"webpack": "^4.28.0"
},
"dependencies": {
@@ -12,7 +12,7 @@ class Badge extends React.Component {
/**
* The visual style of the badge
*
* @type {('primary'|'secondary'|'success'|'danger'|'warning'|'info|'light'|'dark')}
* @type {('primary'|'secondary'|'success'|'danger'|'warning'|'info'|'light'|'dark')}
*/
variant: PropTypes.string,

@@ -0,0 +1 @@
!lib/

This file was deleted.

@@ -1,34 +1,5 @@
# NOTE
This is mainly the v0.32 typings with a few updates for v1. The level of v1 compliance will improve over time.

Below is a list of components that have started to be updated/checked and (at least to some extent) to work:
This is mainly the v0.32 typings with simple updates for v1.

* Container (renamed from Grid)
* Col
* Row
* Dropdown (inc .Toggle .Menu, .Item)
* NavDropdown (inc. Item)
* Navbar (inc .Brand .Toggle .Collapse)
* ButtonGroup
* Button

Many other v0.32 definitions may work for you 'out of the box' or with minor edits.

The readme.md for v0.32 follows.

# Installation
> `npm install --save @types/react-bootstrap`
# Summary
This package contains type definitions for react-bootstrap (https://github.com/react-bootstrap/react-bootstrap).

# Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-bootstrap

Additional Details
* Last updated: Wed, 10 Oct 2018 20:07:15 GMT
* Dependencies: react
* Global values: none

# Credits
These definitions were written by Walker Burgin <https://github.com/walkerburgin>, Vincent Siao <https://github.com/vsiao>, Danilo Barros <https://github.com/danilojrr>, Batbold Gansukh <https://github.com/Batbold-Gansukh>, Raymond May Jr. <https://github.com/octatone>, Cheng Sieu Ly <https://github.com/chengsieuly>, Mercedes Retolaza <https://github.com/mretolaza>, Kat Busch <https://github.com/katbusch>, Vito Samson <https://github.com/vitosamson>, Karol Janyst <https://github.com/LKay>, Aaron Beall <https://github.com/aaronbeall>, Johann Rakotoharisoa <https://github.com/jrakotoharisoa>, Andrew Makarov <https://github.com/r3nya>, Duong Tran <https://github.com/t49tran>.
The level of v1 compliance will improve over time.

This file was deleted.

@@ -1,15 +1,38 @@
import * as React from 'react';
import { Sizes } from 'react-bootstrap';

declare namespace Alert {
export interface AlertProps extends React.HTMLProps<Alert> {
bsSize?: Sizes;
bsStyle?: string;
closeLabel?: string;
/** @deprecated since v0.29.0 */dismissAfter?: number;
// TODO: Add more specific type
onDismiss?: Function;
}

import SafeAnchor from './SafeAnchor';

import { BsPrefixComponent } from './helpers';

declare class AlertLink<
As extends React.ReactType = typeof SafeAnchor
> extends BsPrefixComponent<As> {}

declare class AlertHeading<
As extends React.ReactType = 'div'
> extends BsPrefixComponent<As> {}

interface AlertProps extends React.HTMLProps<Alert> {
bsPrefix?: string;
variant?:
| 'primary'
| 'secondary'
| 'success'
| 'danger'
| 'warning'
| 'info'
| 'dark'
| 'light';
dismissible?: boolean;
show?: boolean;
onClose?: () => void;
closeLabel?: string;
transition?: React.ReactType;
}

declare class Alert extends React.Component<AlertProps> {
static Link: typeof AlertLink;
static Heading: typeof AlertHeading;
}
declare class Alert extends React.Component<Alert.AlertProps> { }
export = Alert;

export default Alert;
@@ -1,10 +1,19 @@
import * as React from 'react';

declare namespace Badge {
export interface BadgeProps extends React.HTMLProps<Badge> {
bsClass?: string;
pullRight?: boolean;
}
interface BadgeProps extends React.HTMLProps<Badge> {
bsPrefix?: string;
variant?:
| 'primary'
| 'secondary'
| 'success'
| 'danger'
| 'warning'
| 'info'
| 'light'
| 'dark';
pill?: boolean;
}
declare class Badge extends React.Component<Badge.BadgeProps> { }
export = Badge;

declare class Badge extends React.Component<BadgeProps> {}

export default Badge;
@@ -1,12 +1,18 @@
import * as React from 'react';
import * as BreadcrumbItem from './BreadcrumbItem';

declare namespace Breadcrumb {
interface BreadcrumbProps extends React.HTMLProps<Breadcrumb> {
bsClass?: string;
}
import { default as BreadcrumbItem } from './BreadcrumbItem';

import { BsPrefixComponent } from './helpers';

interface BreadcrumbProps {
label?: string;
listProps?: React.OlHTMLAttributes<any>;
}
declare class Breadcrumb extends React.Component<Breadcrumb.BreadcrumbProps> {
public static Item: typeof BreadcrumbItem;

declare class Breadcrumb<
As extends React.ReactType = 'nav'
> extends BsPrefixComponent<As, BreadcrumbProps> {
static Item: typeof BreadcrumbItem;
}
export = Breadcrumb;

export default Breadcrumb;
@@ -1,12 +1,16 @@
import * as React from 'react';

declare namespace BreadcrumbItem {
export interface BreadcrumbItemProps extends React.Props<BreadcrumbItem> {
active?: boolean;
href?: string;
title?: React.ReactNode;
target?: string;
}
import { BsPrefixComponent } from './helpers';

interface BreadcrumbItemProps {
active?: boolean;
href?: string;
target?: string;
title?: React.ReactNode;
}
declare class BreadcrumbItem extends React.Component<BreadcrumbItem.BreadcrumbItemProps> { }
export = BreadcrumbItem;

declare class BreadcrumbItem<
As extends React.ReactType = 'li'
> extends BsPrefixComponent<As, BreadcrumbItemProps> {}

export default BreadcrumbItem;
@@ -1,16 +1,36 @@
import * as React from 'react';
import { Sizes } from 'react-bootstrap';

declare namespace Button {
export interface ButtonProps extends React.HTMLProps<Button> {
bsClass?: string;
active?: boolean;
block?: boolean;
bsStyle?: string | null;
bsSize?: Sizes;
componentClass?: React.ReactType;
disabled?: boolean;
}
import { BsPrefixComponent } from './helpers';

interface ButtonProps {
active?: boolean;
block?: boolean;
variant?:
| 'primary'
| 'secondary'
| 'success'
| 'danger'
| 'warning'
| 'info'
| 'dark'
| 'light'
| 'link'
| 'outline-primary'
| 'outline-secondary'
| 'outline-success'
| 'outline-danger'
| 'outline-warning'
| 'outline-info'
| 'outline-dark'
| 'outline-light';
size?: 'sm' | 'lg';
type?: 'button' | 'reset' | 'submit';
href?: string;
disabled?: boolean;
}
declare class Button extends React.Component<Button.ButtonProps> { }
export = Button;

declare class Button<
As extends React.ReactType = 'button'
> extends BsPrefixComponent<As, ButtonProps> {}

export default Button;
@@ -1,14 +1,16 @@
import * as React from 'react';
import { Sizes } from 'react-bootstrap';

declare namespace ButtonGroup {
export interface ButtonGroupProps extends React.HTMLProps<ButtonGroup> {
block?: boolean;
bsSize?: Sizes;
bsStyle?: string;
justified?: boolean;
vertical?: boolean;
}

import { BsPrefixComponent } from './helpers';

interface ButtonGroupProps {
role?: string;
size?: 'sm' | 'lg';
toggle?: boolean;
vertical?: boolean;
}
declare class ButtonGroup extends React.Component<ButtonGroup.ButtonGroupProps> { }
export = ButtonGroup;

declare class ButtonGroup<
As extends React.ReactType = 'div'
> extends BsPrefixComponent<As, ButtonGroupProps> {}

export default ButtonGroup;
@@ -1,14 +1,14 @@
import * as React from 'react';
import { Sizes } from 'react-bootstrap';

declare namespace ButtonToolbar {
export interface ButtonToolbarProps extends React.HTMLProps<ButtonToolbar> {
block?: boolean;
bsSize?: Sizes;
bsStyle?: string;
justified?: boolean;
vertical?: boolean;
}

import { BsPrefixComponent } from './helpers';

interface ButtonToolbarProps {
role?: string;
}
declare class ButtonToolbar extends React.Component<ButtonToolbar.ButtonToolbarProps> { }
export = ButtonToolbar;

declare class ButtonToolbar extends BsPrefixComponent<
'div',
ButtonToolbarProps
> {}

export default ButtonToolbar;

0 comments on commit 2079b22

Please sign in to comment.
You can’t perform that action at this time.