flowtype

Flowtype array of object type does not allow extra properties

无人久伴 提交于 2021-02-18 12:12:13
问题 I am having a strange error with flow. I'm simply trying to have a function that accepts an array of objects with an amount property but I'm having errors when providing objects with more properties. const sum = (items: Array<{amount: number}>) => {/* something */} type Item = { amount: number, name: string }; const list: Array<Item> = []; sum(list); This gives me the following errors: 10: const list: Array<Item> = []; ^ property `name`. Property not found in 2: const sum = (items: Array<

How to use typescript/flow in nodejs without compiling it

天大地大妈咪最大 提交于 2021-02-16 13:29:27
问题 Can someone give me some advice or links for discussion on whether I should bundle JS for backend? I tried to Google with this title (and similar words) and I can't get any useful links. Just want to know, say I am using latest Node.JS (es6-ready), should I bundle/compile the JS? If not, how am I suppose to use typescript/flow? Thank you. 回答1: I feel like you are asking two different questions. I'll try to answer both. How can I just run TypeScript code? This is the one your question's title

How to use typescript/flow in nodejs without compiling it

為{幸葍}努か 提交于 2021-02-16 13:29:10
问题 Can someone give me some advice or links for discussion on whether I should bundle JS for backend? I tried to Google with this title (and similar words) and I can't get any useful links. Just want to know, say I am using latest Node.JS (es6-ready), should I bundle/compile the JS? If not, how am I suppose to use typescript/flow? Thank you. 回答1: I feel like you are asking two different questions. I'll try to answer both. How can I just run TypeScript code? This is the one your question's title

Flow Type complains about class property assigned via react ref

◇◆丶佛笑我妖孽 提交于 2021-02-11 14:39:42
问题 I've started using Flow type on top of a project created with create-react-app tool. I struggle to make a simple scenario work where a class property is filled with element reference in render method but throws 2 errors. What am I doing wrong? All the checks should prevent those warnings. class MyComponent extends React.Component<*> { input: ?HTMLInputElement; componentDidUpdate = () => { if (this.input) { this.input.focus(); if (this.input.value) { const valueLength = this.input.value.length

SCSS Modules Giving Flow error

余生颓废 提交于 2021-02-07 22:03:57
问题 Updated to Create React App 2 which supports css modules via the following import statement: import styles from "./myStyles.module.scss"; However, flow is complaining saying this: Importing from an untyped module makes it any and is not safe! Did you mean to add // @flow to the top of ./myStyles.module.scss? (untyped-import) This is what the [options] in my .flowconfig file looks like: module.file_ext=.js module.file_ext=.jsx module.file_ext=.scss I've also tried adding the following line:

SCSS Modules Giving Flow error

落爺英雄遲暮 提交于 2021-02-07 22:01:08
问题 Updated to Create React App 2 which supports css modules via the following import statement: import styles from "./myStyles.module.scss"; However, flow is complaining saying this: Importing from an untyped module makes it any and is not safe! Did you mean to add // @flow to the top of ./myStyles.module.scss? (untyped-import) This is what the [options] in my .flowconfig file looks like: module.file_ext=.js module.file_ext=.jsx module.file_ext=.scss I've also tried adding the following line:

Refining mixed to a known object type in Flow

北城余情 提交于 2021-02-07 20:52:56
问题 We're trying to do type refinement in Flow to guard against values entering our application at the external interfaces. To do this we're using mixed and then trying to refine to known types, but Flow isn't make it easy! The following seems like it should work, I've validated that the mixed type value matches the requirements of the response type. type Response = { head: string } const refineToResponse = (value: mixed): ?Response => { if (value && typeof value === "object" && typeof value.head

Refining mixed to a known object type in Flow

喜夏-厌秋 提交于 2021-02-07 20:52:49
问题 We're trying to do type refinement in Flow to guard against values entering our application at the external interfaces. To do this we're using mixed and then trying to refine to known types, but Flow isn't make it easy! The following seems like it should work, I've validated that the mixed type value matches the requirements of the response type. type Response = { head: string } const refineToResponse = (value: mixed): ?Response => { if (value && typeof value === "object" && typeof value.head

SVG types support in Flow.js?

别来无恙 提交于 2021-02-05 10:42:06
问题 I've looked around at various github threads and it seems as if SVG support is not merged / shipped in current versions of Flow.js (I'm using VS Code extension vscode-flow-ide ). I'm trying to work with SVG refs and for now have had to use a mix of less-specific type ( Element ) and // $FlowFixMe to work around these - not ideal from a broader type-safety perspective. Anyone solved this? I'm using /flow/lib/dom.js currently, but it lacks these types. 回答1: Interrim solution until the official

What do the ellipsis do in Flow type declarations?

三世轮回 提交于 2021-02-05 05:37:27
问题 What are the ellipsis called in the following Flow code and what do they do? export type ListTypeNode = { +kind: 'ListType', +loc?: Location, +type: TypeNode, ... }; 回答1: This is the new syntax in Flow, that in the future will be indicating, that this object type is inexact (when the regular annotation by default will be exact object annotation). In a few releases, Flow will begin to treat {foo: number} as an exact object. To indicate inexactness, you must add an ellipsis to the end of an