Skip to content

Commit 125ad6a

Browse files
panagosg7meta-codesync[bot]
authored andcommitted
[flow] remove check on keys of Omit
Summary: This now matches TypeScript's behavior: https://www.typescriptlang.org/play/?#code/C4TwDgpgBAglC8UDyBbAlsAPAbwL4BooByAQyID4BuAKAGMB7AOwGdgoSAuWBKPSoA Changelog: [errors] the `Omit<O, K>` utility type will not enforce that the provided keys `K` need to be part of `O`. Reviewed By: gkz Differential Revision: D89563453 fbshipit-source-id: 363623b3faf51bca89f4c69872bc9867cf101825
1 parent 0688a71 commit 125ad6a

File tree

6 files changed

+31
-62
lines changed

6 files changed

+31
-62
lines changed

lib/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3184,7 +3184,7 @@ type Pick<O: interface {}, Keys: $Keys<O>> = {[key in Keys]: O[key]};
31843184
/**
31853185
* Omit specific fields from an object, e.g. Omit<O, 'foo' | 'bar'>
31863186
*/
3187-
type Omit<O: interface {}, Keys: $Keys<O>> = $Omit<O, Keys>;
3187+
type Omit<O: interface {}, Keys> = $Omit<O, Keys>;
31883188

31893189
/**
31903190
* Construct an object type using string literals as keys with the given type,

tests/mapped_type_utilities/mapped_type_utilities.exp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,6 @@ References:
122122
^^^^^^^^ [2]
123123

124124

125-
Error ---------------------------------------------------------------------------------------------------- omit.js:65:43
126-
127-
Cannot instantiate `Omit` because in type argument `Keys`: property `xxx` is missing in object type [1]. [prop-missing]
128-
129-
omit.js:65:43
130-
65| declare const x: Omit<{foo: 1, bar: 2}, 'xxx'>; // ERROR
131-
^^^^^
132-
133-
References:
134-
omit.js:65:25
135-
65| declare const x: Omit<{foo: 1, bar: 2}, 'xxx'>; // ERROR
136-
^^^^^^^^^^^^^^^^ [1]
137-
138-
139125
Error ----------------------------------------------------------------------------------------------------- pick.js:8:10
140126

141127
Cannot assign `3` to `pickedO1.foo` because property `foo` is not writable. [cannot-write]
@@ -243,4 +229,4 @@ References:
243229

244230

245231

246-
Found 16 errors
232+
Found 15 errors

tests/mapped_type_utilities/omit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ type OmitInstance = Omit<C, 'foo'>;
6262

6363
// Omitting non-existent property
6464
{
65-
declare const x: Omit<{foo: 1, bar: 2}, 'xxx'>; // ERROR
65+
declare const x: Omit<{foo: 1, bar: 2}, 'xxx'>; // OK
6666
}

tests/records/records.exp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,9 @@ Operation `Omit` [1] is not allowed on record `R` [2]. To fix, turn the record t
273273
^ [2]
274274

275275
References:
276-
<BUILTINS>/core.js:3187:46
277-
3187| type Omit<O: interface {}, Keys: $Keys<O>> = $Omit<O, Keys>;
278-
^^^^^^^^^^^^^^ [1]
276+
<BUILTINS>/core.js:3187:36
277+
3187| type Omit<O: interface {}, Keys> = $Omit<O, Keys>;
278+
^^^^^^^^^^^^^^ [1]
279279

280280

281281
Error -------------------------------------------------------------------------------------------- declaration.js:418:24

tests/type_destructors/tvar4.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ function fn3<T: {p: any}>(a: T => void): (Omit<T, 'p'>) => void {
3232
// number, but we expect a string.
3333
fn3((x: {foo: string, p: number}) => {})({foo: 42});
3434

35-
// We error here because $Rest requires us to specify a p property in our object
36-
// type. But if we look at the implementation of fn3 this is a fine program
37-
// to accept.
38-
fn3((x: {foo: number}) => {})({foo: 42});
35+
fn3((x: {foo: number}) => {})({foo: 42}); // OK
3936

4037
function fn4<T: {|p: any|}>(a: T => void): (T['p']) => void {
4138
// We error here because the implementation of {p: empty} ~> empty currently

tests/type_destructors/type_destructors.exp

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -390,27 +390,13 @@ References:
390390
^^^^^^ [2]
391391

392392

393-
Error ---------------------------------------------------------------------------------------------------- tvar4.js:38:1
394-
395-
Cannot call `fn3` because in type argument `Keys`: property `p` is missing in object type [1]. [prop-missing]
396-
397-
tvar4.js:38:1
398-
38| fn3((x: {foo: number}) => {})({foo: 42});
399-
^^^
400-
401-
References:
402-
tvar4.js:38:9
403-
38| fn3((x: {foo: number}) => {})({foo: 42});
404-
^^^^^^^^^^^^^ [1]
405-
406-
407-
Error ---------------------------------------------------------------------------------------------------- tvar4.js:38:9
393+
Error ---------------------------------------------------------------------------------------------------- tvar4.js:35:9
408394

409395
Cannot call `fn3` because in type argument `T`: property `p` is missing in object type [1] but exists in object
410396
type [2]. [incompatible-type]
411397

412-
tvar4.js:38:9
413-
38| fn3((x: {foo: number}) => {})({foo: 42});
398+
tvar4.js:35:9
399+
35| fn3((x: {foo: number}) => {})({foo: 42}); // OK
414400
^^^^^^^^^^^^^ [1]
415401

416402
References:
@@ -419,62 +405,62 @@ References:
419405
^^^^^^^^ [2]
420406

421407

422-
Error --------------------------------------------------------------------------------------------------- tvar4.js:43:17
408+
Error --------------------------------------------------------------------------------------------------- tvar4.js:40:17
423409

424410
Cannot call `a` with object literal bound to the first parameter because object literal [1] is incompatible with
425411
`T` [2]. [incompatible-type]
426412

427-
tvar4.js:43:17
428-
43| return p => a({p});
413+
tvar4.js:40:17
414+
40| return p => a({p});
429415
^^^ [1]
430416

431417
References:
432-
tvar4.js:40:32
433-
40| function fn4<T: {|p: any|}>(a: T => void): (T['p']) => void {
418+
tvar4.js:37:32
419+
37| function fn4<T: {|p: any|}>(a: T => void): (T['p']) => void {
434420
^ [2]
435421

436422

437-
Error --------------------------------------------------------------------------------------------------- tvar4.js:47:31
423+
Error --------------------------------------------------------------------------------------------------- tvar4.js:44:31
438424

439425
Cannot call `fn4(...)` with `42` bound to the first parameter because number [1] is incompatible with string [2].
440426
[incompatible-type]
441427

442-
tvar4.js:47:31
443-
47| fn4((x: {|p: string|}) => {})(42);
428+
tvar4.js:44:31
429+
44| fn4((x: {|p: string|}) => {})(42);
444430
^^ [1]
445431

446432
References:
447-
tvar4.js:47:14
448-
47| fn4((x: {|p: string|}) => {})(42);
433+
tvar4.js:44:14
434+
44| fn4((x: {|p: string|}) => {})(42);
449435
^^^^^^ [2]
450436

451437

452-
Error ---------------------------------------------------------------------------------------------------- tvar4.js:51:1
438+
Error ---------------------------------------------------------------------------------------------------- tvar4.js:48:1
453439

454440
Cannot call `fn4` because property `p` is missing in object type [1]. [prop-missing]
455441

456-
tvar4.js:51:1
457-
51| fn4((x: {||}) => {})(42);
442+
tvar4.js:48:1
443+
48| fn4((x: {||}) => {})(42);
458444
^^^
459445

460446
References:
461-
tvar4.js:51:9
462-
51| fn4((x: {||}) => {})(42);
447+
tvar4.js:48:9
448+
48| fn4((x: {||}) => {})(42);
463449
^^^^ [1]
464450

465451

466-
Error ---------------------------------------------------------------------------------------------------- tvar4.js:51:9
452+
Error ---------------------------------------------------------------------------------------------------- tvar4.js:48:9
467453

468454
Cannot call `fn4` because in type argument `T`: property `p` is missing in object type [1] but exists in object
469455
type [2]. [incompatible-type]
470456

471-
tvar4.js:51:9
472-
51| fn4((x: {||}) => {})(42);
457+
tvar4.js:48:9
458+
48| fn4((x: {||}) => {})(42);
473459
^^^^ [1]
474460

475461
References:
476-
tvar4.js:40:17
477-
40| function fn4<T: {|p: any|}>(a: T => void): (T['p']) => void {
462+
tvar4.js:37:17
463+
37| function fn4<T: {|p: any|}>(a: T => void): (T['p']) => void {
478464
^^^^^^^^^^ [2]
479465

480466

@@ -598,4 +584,4 @@ References:
598584

599585

600586

601-
Found 38 errors
587+
Found 37 errors

0 commit comments

Comments
 (0)