flow-codemorphs
general purpose codemods for flow
Table of Contents
makeExact
Converts object shape types to exact objects.
Options
ambiguousOnly
- if truthy, only ambiguous object shape types will be converted.
You can pass selectionStart
and selectionEnd
options to only convert types within that
range. If selectionStart === selectionEnd
, only converts the type annotation containing
the cursor, unless no type annotation contains the cursor, in which case it converts
everything.
Example
Before
// @flow
type Foo = {
bar: number,
baz: Array<{
qux: number,
blah: $ReadOnly<{
blsdf: string,
}>,
glorb: {a: number}[],
...
}>,
}
Command
jscodeshift -t path/to/flow-codemorphs/makeExact.js <file>
After
// @flow
type Foo = {|
bar: number,
baz: Array<{|
qux: number,
blah: $ReadOnly<{| blsdf: string |}>,
glorb: {| a: number |}[],
|}>,
|}
makeInexact
Converts object shape types to inexact objects.
Options
ambiguousOnly
- if truthy, only ambiguous object shape types will be converted.
You can pass selectionStart
and selectionEnd
options to only convert types within that
range. If selectionStart === selectionEnd
, only converts the type annotation containing
the cursor, unless no type annotation contains the cursor, in which case it converts
everything.
Example
Before
// @flow
type Foo = {|
bar: number,
baz: Array<{
qux: number,
blah: $ReadOnly<{|
blsdf: string,
|}>,
glorb: {a: number}[],
...
}>,
|}
Command
jscodeshift -t path/to/flow-codemorphs/makeInexact.js <file>
After
// @flow
type Foo = {
bar: number,
baz: Array<{
qux: number,
blah: $ReadOnly<{ blsdf: string, ... }>,
glorb: { a: number, ... }[],
...
}>,
...
}
makeReadOnly
Converts mutable object shape and array types to readonly types.
Options
You can pass selectionStart
and selectionEnd
options to only convert types within that
range. If selectionStart === selectionEnd
, only converts the type annotation containing
the cursor, unless no type annotation contains the cursor, in which case it converts
everything.
Example
Before
// @flow
type Foo = {
bar: number
baz: Array<{
qux: number
blah: $ReadOnly<{
blsdf: string
}>
glorb: { a: number }[]
}>
}
Command
jscodeshift -t path/to/flow-codemorphs/makeReadOnly.js <file>
After
// @flow
type Foo = $ReadOnly<{
bar: number
baz: $ReadOnlyArray<
$ReadOnly<{
qux: number
blah: $ReadOnly<{
blsdf: string
}>
glorb: $ReadOnlyArray<$ReadOnly<{ a: number }>>
}>
>
}>