Typeguards
function isMap(maybeMap: any): maybeMap is Map<any, any>;keyof
| const style = document.createElement('style'); | |
| style.innerText = ` | |
| .text-base { | |
| max-width: 100% !important; | |
| padding-left: 20px !important; | |
| padding-right: 20px !important; | |
| } | |
| `; | |
| document.head.appendChild(style); |
Typeguards
function isMap(maybeMap: any): maybeMap is Map<any, any>;keyof
Generics are a mechanism to provide typings for a component after you have defined the type or interface.
Imagine we are creating an Input component in react that has a has a default value that can be of type string | number | Moment | boolean the way of typing this without generics would be like this:
interface Input {
name: string,
defaultValue: string | number | Moment | boolean,
required: boolean,
id: stringThis is in reference to a change pull request.
original
withReducer<any, any>("FormState", "dispatch", withReducerState, Map()))changed
withReducer("FormState", "dispatch", withReducerState, Map()))| {"lastUpload":"2017-02-28T04:00:45.232Z","extensionVersion":"v2.5.1"} |
| import React from "react"; | |
| import { getData } from "../../common/request"; | |
| import CSS from "../../less/main.less"; | |
| var Modal = require("../../components/model.jsx"); | |
| import Article from "../../components/article.jsx" | |
| import ArticleImage1 from "../../images/article1.jpeg"; |
| import React from "react"; | |
| import classnames from "classnames"; | |
| import CSS from "../less/modal.less"; | |
| import close from "../images/cross.svg"; | |
| var eventPrefix = "Modal"; | |
| export default class Modal extends React.Component { |
| module.exports = function (formNodes) { | |
| let formObject = {}; | |
| for (let i = 0; i < formNodes.length; i++) { | |
| if (formNodes[i].nodeName === "INPUT" || formNodes[i].nodeName === "SELECT") { | |
| formObject[formNodes[i].id] = formNodes[i].value; | |
| } | |
| } | |
| return formObject; | |
| }; |
| for (var i = 0; i < recipes.length; i++) { | |
| if (recipes[i][recipeProperty] !== undefined && recipes[i][recipeProperty].length > 0) { | |
| filterArray = filterArray.concat(recipes[i][recipeProperty]); | |
| } | |
| } |