Open JoshuaKGoldberg opened 3 years ago
A summary of all the resultant operations that exist today in core fixers...
const names = []
-> const names: string[] = []
class NameGreeter extends Component
-> interface NameGreeterProps { ... }; class NameGreeter extends Component<NameGreeterProps>
const NamedGreeter = ({ ... }) => {
-> interface NamedGreeterProps { ... }; const NamedGreeter: React.FC<NamedGreeterProps> = ({ ... }) => {
MyClass extends HasTypeParameter
-> MyClass extends HasTypeParameter<number>
const names = new Map()
-> const names = new Map<string>()
function announceValue(value: string) {
-> function announceValue(value: string | number) {
public value: number
-> public value: number | string
function createValue(): number
-> function createValue(): number | string
const value: number
-> const value: number | string
class MyClass { ... }
-> class MyClass { happy: boolean; ... }
Sourced entirely from TypeScript's language server suggestions
function withValue(value) {
-> function withValue(value: number) {
public name
-> public name: string
let name
-> let name: string
Sourced entirely from TypeScript's language server suggestions
this
) in a function declaration: e.g. function scoped() {
-> function scoped(this: Container) {
function withValue(value: number = 0) {
-> function withValue(value = 0) {
public name: number = 0
-> public name = 0
let name: number = 0
-> let name = 0
!
operator: e.g. let name: string = null
-> let name: string = null!
| null
and/or | undefined
: e.g. let name: string = null
-> let name: string | null = null
Given the above, these are all the unique operations I can think of.
These already exist:
These seem like ones that are likely to be needed eventually:
The standard getNoImplicitAnyMutations:
Uses the standard getNoImplicitAnyMutations
Uses the standard getNoImplicitAnyMutations
Uses the standard getNoImplicitAnyMutations
The standard getNoImplicitThisMutations:
Uses the standard getNoImplicitAnyMutations
Basically the same as fixNoInferableTypesParameters
Basically the same as fixNoInferableTypesParameters
!
!
:
!
to the variable!
before the access!
collectReturningNodeExpressions
)React components inside fixIncompleteTypes have a lot of searching logic that ends up only looking at JSX attributes. This should be generalized but it would be difficult to make a general non-React function understand JSX usage. Perhaps adding in harded "oh this seems like a JSX/React component" logic would be enough?
Overview
I'm finding TypeStat to be suffering under its own code bloat for two major reasons:
|
union types to a declaration; adding in extra interface properties; ...any
to a real type; removing unused|
union types; ...Approach
I'd like to take roughly the following rearchitecture approach:
isAssignableTo
is public!Abstracting fixers into common operations instead of keying them into their own text printing comes with a couple of key advantages:
20: making it easier to overhaul the underlying text mutator
This issue replaces the more specific #124. Long term, I'd like to turn this into some kind of monorepo where the shared helpers can be exported as a standalone package for the community. That'll be a followup issue.