Skip to content

Commit

Permalink
[flow] Add tests to assert the current typing behavior for the ref pr…
Browse files Browse the repository at this point in the history
…op in component type

Summary:
Right now, it will produce good errors during subtyping, but has weird behavior in implicit instantiation.

I want to fix it, but let's first assert the current behavior, so we can easily see the improvement later.

Changelog: [internal]

Reviewed By: panagosg7

Differential Revision: D63154627

fbshipit-source-id: 7f4535592159d1f9a35e79c69eeb2693db6c35a1
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Sep 21, 2024
1 parent 80addb6 commit 7a956a7
Show file tree
Hide file tree
Showing 7 changed files with 499 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/component_type/.flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[options]
component_syntax=true
all=true
no_flowlib=false
15 changes: 15 additions & 0 deletions tests/component_type/abstract_component_to_component_type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
declare const Foo: React.AbstractComponent<{+bar: string}, Instance>;
declare class Instance {}
declare class ImNotARefSetter {}

Foo as component(bar: string, ref: React.RefSetter<Instance>); // ok
Foo as component(bar: number, ref: React.RefSetter<Instance>); // error: number ~> string
Foo as component(ref: React.RefSetter<Instance>, ...{bar: number}); // error: number ~> string
Foo as component( // error: Instance ~> string
bar: string,
ref: React.RefSetter<string>
);
Foo as component(
bar: string,
ref: ImNotARefSetter // error: bad ref
);
14 changes: 14 additions & 0 deletions tests/component_type/class_to_component_type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
declare class Foo extends React$Component<{bar: string}> {}
declare class ImNotARefSetter {}

Foo as component(bar: string, ref: React.RefSetter<Foo>); // ok
Foo as component(bar: number, ref: React.RefSetter<Foo>); // error: number ~> string
Foo as component(ref: React.RefSetter<Foo>, ...{bar: number}); // error: number ~> string
Foo as component( // error: Foo ~> string
bar: string,
ref: React.RefSetter<string>
);
Foo as component(
bar: string,
ref: ImNotARefSetter // error: bad ref
);
Loading

0 comments on commit 7a956a7

Please sign in to comment.