Skip to content

[TypeScript]: autocomplete is not available on ContextValue<T, E> #9422

@unional

Description

@unional

Provide a general summary of the issue here

This is because it is written as:

type SlottedContextValue<T> = SlottedValue<T> | T | null | undefined;
export type ContextValue<T, E> = SlottedContextValue<WithRef<T, E>>;

Looking at the type, my guess is SlottedContextValue should be:

type SlottedContextValue<T> = SlottedValue<T> & T | null | undefined;

May be a mistake?
I can open a PR for it.

🤔 Expected Behavior?

Autocompletion should be available to the value of type ContextValue<T, E>.

type MyProps = { a: string }

type MyContextValue = ContextValue<MyCompProps, HTMLDivElement>

const MyContext = createContext<MyContextValue>(null)


function Comp() {
  return (
    <MyContext.Consumer>
      {(context) => {
         // autocompletion is not available
         console.log(context.a)
         return <div>{context}</div>
      }}
    </MyContext.Consumer>
  )
}

😯 Current Behavior

see above

💁 Possible Solution

see above

🔦 Context

No response

🖥️ Steps to Reproduce

See above

Version

1.14.0

What browsers are you seeing the problem on?

Other

If other, please specify.

code

What operating system are you using?

macos

🧢 Your Company/Team

Palo Alto Networks

🕷 Tracking Issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions