microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.72k stars 12.45k forks source link

Completion does not work for generic type extending tuple or array of all partial type #45617

Open ishowta opened 3 years ago

ishowta commented 3 years ago

Bug Report

πŸ”Ž Search Terms

auto completion, suggestion, tuple, array, mapped types

πŸ•— Version & Regression Information

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

// It doesn't work

type BaseTheme = {
  component?: string
}

declare function extendTheme<
  Extensions extends [BaseTheme & Record<string, unknown>]
>(extensions: Extensions): void

extendTheme([{
  /* Can't autocomplete here */
}])

// list also doesn't work

type BaseTheme2 = {
  component?: string
}

declare function extendTheme2<
  Extensions extends (BaseTheme2 & Record<string, unknown>)[]
>(extensions: Extensions): void

extendTheme2([{
  /* Can't autocomplete here */
}])

// with required field works

type BaseTheme3 = {
  component?: string
  requiredField: string
}

declare function extendTheme3<
  Extensions extends [BaseTheme3 & Record<string, unknown>]
>(extensions: Extensions): void

extendTheme3([{
  /* Can autocomplete here */
}])

// but with required field and complete required field doesn't work

type BaseTheme4 = {
  component?: string
  requiredField: string
}

declare function extendTheme4<
  Extensions extends [BaseTheme4 & Record<string, unknown>]
>(extensions: Extensions): Extensions

extendTheme4([{
  requiredField: 'foo',
  /* Can't autocomplete here */
}])

// also BaseTheme with no mapped types doesn't work too

declare function extendTheme4WithNoMapped<
  Extensions extends [BaseTheme4]
>(extensions: Extensions): Extensions

extendTheme4WithNoMapped([{
  requiredField: 'foo',
  /* Can't autocomplete here */
}])

// no extend tuple works

type BaseTheme5 = {
  component?: string
}

declare function extendTheme5<
  Extensions extends BaseTheme5
>(extensions: [Extensions]): Extensions

extendTheme5([{
  /* Can autocomplete here */
}])

πŸ™ Actual behavior

No autocomplete

πŸ™‚ Expected behavior

Autocomplete

andrewbranch commented 3 years ago

Probably related to https://github.com/microsoft/TypeScript/pull/33937

ishowta commented 3 years ago

~Sorry, the mapped type was not relevant to this problem, so I removed it to simplify problem. (BaseTheme & Record<string, unknown => BaseTheme)~

edit: Some patterns did not work without the mapped type, but others did.