luau-lang / luau

A fast, small, safe, gradually typed embeddable scripting language derived from Lua
https://luau.org
MIT License
3.98k stars 373 forks source link

Autocomplete doesn't work with some intersection/union types #1242

Open grilme99 opened 5 months ago

grilme99 commented 5 months ago

I'm not sure about terminology or what exactly is causing this, but there are some edge cases around intersections and/or unions that cause autocomplete to break. Below is a minimal repro, but this bug is notably affecting React prop autocomplete as well as various other parts of our codebases.

In this sample, flex and flexBasis will not autocomplete inside of style.

type ViewStyle = {
    flex: number,
    flexBasis: number,
}

type RecursiveArray<T> = { T | RecursiveArray<T> }
export type StyleProp<T> = T | RecursiveArray<T>

export type ViewProps = {
    style: StyleProp<ViewStyle>?,
}

local _props: ViewProps = {
    style = {

    }
}

The type of ViewProps is:

type ViewProps = {|
    style: (t1 | {|
        flex: number,
        flexBasis: number
    |})?
|} where t1 = {t1 | {|
    flex: number,
    flexBasis: number
|}}