gkz Github contribution chart
gkz Github Stats
gkz Most Used Languages

Activity

30 Aug 2022

Issue Comment

Gkz

Overloaded function is not refining maybe type

Flow version: v0.130.0

Expected behavior

I have the following validation function:

declare function isValidUUID(value :null) :false;
declare function isValidUUID(value :void) :false;
declare function isValidUUID(value :mixed) :boolean;

const UUID_PATTERN = /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i;
function isValidUUID(value) {
  return value && UUID_PATTERN.test(value);
} 

The goal is to validate a value and pass it on to a React component.

let orgId :?UUID;
if (isValidUUID(orgId)) {
  return (
    <OrgContainer orgId={orgId} />
  );
} 

The expected behavior is for Flow to refine orgId as not null or undefined because the only way to enter the if body is when orgId is defined. I've tried various approaches to typing isValidUUID... using an interface, using %checks... haven't been successful.

Actual behavior

Flow gives the following error:

Cannot create `OrgContainer` element because null or undefined [1] is incompatible with string [2] in property `orgId`. [incompatible-type] 

https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVBLAtgBzgJwBcwAlAUwEMBjYqfOLMAcn0pqYG50ATMqmCqzCEAnjjJgAqpICSAETABeMAGdC+DADsA5l179BEqAFdNNDHE1gMKgGoUYGbtPkAKAG4PjEgFybjMDAAlGA+UA4qZHp8AkImZoQWVjb2js6ych5evu5wTiFhEVGo+rFGpuaW1nYOTi6ZnjDeoVgYAB5k3AUARnBwMJSaXKhUlmpSGQD6AAoAggAq8wCiJABySmDAAHoA2gAMALQAnLMHAGIAugDeABwAvgf7x6eXVwAsD08n59cfj4ffV5-L4va4ARgATHcACTADBceKVZI1NL1LJNMghK6oMBgViEYz4KyNZoAMlJE3kMwWyzWADpCGQ1OjvEEuHd0KJxGAAPL4bTTeg4FQbbG4gjaGTcUL1dlcUaacZ87QAYUshAoWjI+A2riuYAlUrAd1CysFcGFIUUAD4wGK8WQCUSwK4cbiwAAebgYdzWq6G7h3D3Ab2+t1s1B3YZciSzHA4c3C0VugOhAD8ssj8rGxDjODVmg1Wp1yj1Bv5RpNPjziZUVtt9owUBdKVq6TcAaCWLduPxhKsrvd7o9yoLRc02vLku4in9FcDm2tPbAEdxHN7jv7YH8gTlQA

Forked On 30 Aug 2022 at 05:43:35

Gkz

I would try something like this instead: https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVBLAtgBzgJwBcwAlAUwEMBjYqfOLMAcn0pqYG50ATMqmCqzCEAnjjJgAqpICSAETABeMAGdC+DADsA5l1RU4mtVNlyA+gAUAggBUbAURIA5JWGAA9ANoAGALQBOK18AMQBdAG8ADgBfXx8AoLDwgBZY+MCQiNS4vwyk7PTEiIBGACZogBJgDD0oAFdNGgxDMAA3ChgMbgpCMml5AAp2mDqyAEoALjAAfn6FcNQwMFZCOvxNNo7RsAAyHZN5S1sHZwA6XrUhrfGZzZGJKc06mBguaPRRcTAAeXxtC3oOBUrgWSwI2hk3DAEzmby4BiMxF+2gAwoZCBQtGR8K4BuEwODIWBotDkQC4ECxkoAHxgUHLMirdZgAaLJZgAA83AwrWp4UJ3GiHOA3N5bLGcI+YgkVhwOHJQJBbIF0NmpklCOMspwaM0GKxOOUeIJf0hUywFBEACMyMiiSSJtqFSoqYpafTNcQVcphl0en1TAMLdbbabuBK2RgoCyBVT6UsVmsNqz2eyOcjdfrNNiTRDuIp+WGScBqWylhGlu8E4yk2Ani84UA

Commented On 30 Aug 2022 at 05:43:35
Issue Comment

Gkz

Missing support for Array.prototype.at()

👋

Missing/Incorrect APIs

Missing API: Array.prototype.at()

Relevant documentation

  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at

Flow.org/try

https://flow.org/try/#0MYewdgzgLgBAhgJwXAngRhgXhgbQKwA0MaATEQBxFoDMADEQCwMC6A3AFDsA2AprAJZgAJjwAeWGCQ7tQkELwB0XEAHMAFAAMAqhEEr4YGIJHiQAMxgASAN7GxAXxhQAFjyNQeAWxgI+AVwQwHiEjCCtrRGR0BTgoNTtRAEp7DUSOAHp0mDEABx5gDxCQPygckoAuGAAiHT0DI2ExGHNJJ1d3Lx9-QODQmHIqzgSJAFopTlkIeR4lVU1asH04Q2GWmwTHfg9vXygAoJD+MJtI1DQYuITk1Iys3PzC5pKyqEqa3UX61Ysxjp3ug59Gi0QZAA

5: console.log(`Using an index of ${index} the item returned is ${array1.at(index)}`);
                                                                         ^ Cannot call `array1.at` because property `at` is missing in `Array` [1]. [prop-missing]
References:
[LIB] ..//static/v0.181.2/flowlib/core.js:874: declare class Array<T> extends $ReadOnlyArray<T> {
                                                             ^ [1]
10: console.log(`Using an index of ${index} item returned is ${array1.at(index)}`);
                                                                      ^ Cannot call `array1.at` because property `at` is missing in `Array` [1]. [prop-missing]
References:
[LIB] ..//static/v0.181.2/flowlib/core.js:874: declare class Array<T> extends $ReadOnlyArray<T> {
                                                             ^ [1] 

Forked On 23 Aug 2022 at 07:05:28

Gkz

Yeah it's broken on Try Flow for version 0.185. Works if you switch to master branch however. Don't know why

Commented On 23 Aug 2022 at 07:05:28
Issue Comment

Gkz

parser: add parse-only support for "import.meta"

Summary: Resolves #6913. As with new.target, we can parse the expression, but we fail to typecheck it. Clients can use a suppression comment to ignore uses of import.meta in an otherwise valid file.

The parse error message on inputs like import.notMeta was chosen to be consistent with the message emitted by Babylon.

Test Plan: Unit tests added, and all existing tests pass.

wchargin-branch: parse-import-meta

Forked On 23 Aug 2022 at 06:39:27

Gkz

If I add a [string]: mixed indexer to the type, so you can access random other properties (but they're mixed so you have to refine them first to e.g. a string), would that be fine? We probably don't want to hardcode random specific things like vite env vars in Flow.

So you could do

const env = import.meta.env;
if (typeof env === 'string') {
  // do the stuff
} 

Commented On 23 Aug 2022 at 06:39:27
Issue Comment

Gkz

parser: add parse-only support for "import.meta"

Summary: Resolves #6913. As with new.target, we can parse the expression, but we fail to typecheck it. Clients can use a suppression comment to ignore uses of import.meta in an otherwise valid file.

The parse error message on inputs like import.notMeta was chosen to be consistent with the message emitted by Babylon.

Test Plan: Unit tests added, and all existing tests pass.

wchargin-branch: parse-import-meta

Forked On 23 Aug 2022 at 04:29:51

Gkz

What should that be? Do you have links to documentation?

Commented On 23 Aug 2022 at 04:29:51
Issue Comment

Gkz

Update readme

Minor readme updates

Forked On 11 Aug 2022 at 07:22:07

Gkz

In readme:

Type Assertions

as is TypeScript specific. You can add an example from Flow for our casting syntax: https://flow.org/en/docs/types/casting/

(x: T); 

One can explicitly specify the type arguments of a generic function invocation or generic class instantiation in TypeScript.

You can do the same in Flow, you can make this language more generic.

FAQ

The FAQ needs to also be updated to remove the TS specific language.

Website

The website at https://tc39.es/proposal-type-annotations/ needs a lot of updating as well, in many places. E.g. "That said, the language in this specification favours TypeScript as it is the most popular type-system, but nearly all of the proposed syntax spaces would benefit Flow users too." needs to be completely deleted, along with out language needs to be more generic

Commented On 11 Aug 2022 at 07:22:07

Gkz

Update readme

Minor readme updates

Forked On 11 Aug 2022 at 07:14:43

Gkz

This whole feature is TypeScript specific. We should remove this whole section.
On 11 Aug 2022 at 07:14:43

Gkz

Update readme

Minor readme updates

Merged On 11 Aug 2022 at 07:14:43

Gkz

Commented On 11 Aug 2022 at 07:14:43

Gkz

Update readme

Minor readme updates

Forked On 11 Aug 2022 at 07:11:02

Gkz

I would also add an example of Flow's comment types: https://flow.org/en/docs/types/comments/ ``` function f(value /*: MyAlias */) /*: boolean */ { return value.bar; } ```
On 11 Aug 2022 at 07:11:02

Gkz

Update readme

Minor readme updates

Merged On 11 Aug 2022 at 07:11:03

Gkz

Commented On 11 Aug 2022 at 07:11:03
Issue Comment

Gkz

`exact_empty_objects=true` for conditional objects?

Hello! 👋 I am trying to enable exact_empty_objects=true; however, there are some occurrences of conditionally set object properties in my codebase. Something like this:

const error = {};
error.message = pragma;
if (locations) {
  const groups = locations.groups;
  error.message = groups?.message;
  error.line = Number(groups?.line);
  error.column = Number(groups?.column);
  error.endLine = Number(groups?.endLine);
  error.endColumn = Number(groups?.endColumn);
}
return error; 

See: https://github.com/adeira/universe/blob/9ef855a480e1e4496dbcaca25ac3a4181887767f/src/eslint-fixtures-tester/src/index.js#L21-L31

Flow returns the following errors:

What is the correct approach in this case? What solution do you recommend? Cc @gkz

Forked On 11 Aug 2022 at 07:05:48

Gkz

Hi, I will publish a blog post later this year that will describe how to migrate to enabling exact_empty_objects (including some codemods). If you don't want to wait and don't have many errors, you can fix this manually by adding a type annotation to const error = {};. The properties you add conditionally should be optional

Commented On 11 Aug 2022 at 07:05:48
Issue Comment

Gkz

Unsealed objects are not type-checked

This passes:

const c = {};

c.foo(); 

This doesn't:

const c = { x: 1 };

c.foo(); 

Forked On 13 Jul 2022 at 08:57:39

Gkz

Fixed if you enabled exact_empty_objects=true in your .flowconfig. Announcement will be in the future

Commented On 13 Jul 2022 at 08:57:39
Issue Comment

Gkz

Empty object is valid for non exact type annotation

Flow version: 0.128.0

Expected behavior

Type error

Actual behavior

const someObj: { id: number } = {};
const num: number = someObj.id;
console.log(num); 

num here is undefined, and definitely not a number

  • Link to Try-Flow or Github repo: https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoAxnAdgZwC5g5wC2ApgPIBGAVgFxgDeYAlgCb1YCuxlpATmAC+YALyNBAbgzZ8YLsQ7deAsUTJVqAOjYSgA

Forked On 13 Jul 2022 at 08:57:13

Gkz

Fixed if you enabled exact_empty_objects=true in your .flowconfig. Announcement will be in the future

Commented On 13 Jul 2022 at 08:57:13
Issue Comment

Gkz

Exact type doesn't work with possible empty object

Repro

type A = {| a?: string |};
const x: A = {} // error: object literal. Inexact type is incompatible with exact type 

Flow version 0.36

Forked On 13 Jul 2022 at 08:52:22

Gkz

Fixed if you enable the exact_empty_objects=true in your .flowconfig [options] section.

There will be a blog post announcement in the future

Commented On 13 Jul 2022 at 08:52:22