Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intellisense breaks when omit is used #32289

Closed
mvestergaard opened this issue Jul 8, 2019 · 4 comments
Closed

Intellisense breaks when omit is used #32289

mvestergaard opened this issue Jul 8, 2019 · 4 comments
Labels
Needs Investigation This issue needs a team member to investigate its status.
Milestone

Comments

@mvestergaard
Copy link

I've encountered some issues when using Omit to filter prop types for react components. I was not able to replicate it on the typescript playground, so it appears to only happen for more complex types? I was able to reproduce it when trying to omit certain props from the default props of react-select.

TypeScript Version: Have replicated on 3.3.3, 3.4.5, 3.5.2 and 3.6.0-dev.20190704

Search Terms:
omit intellisense

Code

import React from "react";
import { Props } from "react-select/base";

interface WithoutOmit extends Props {}

export const SelectWithoutOmit: React.FC<WithoutOmit> = ({
    // trigger auto-complete here, works fine

}) => <div />;

interface WithOmit extends Omit<Props, "onChange" | "value"> {}

export const SelectWithOmit: React.FC<WithOmit> = ({
    // trigger auto-complete here, doesn't work
    
}) => <div />;

Reproduction repository can be found here https://github.com/mvestergaard/typescript-omit-repro

Expected behavior:
Intellisense should show available properties when Omit is used

Actual behavior:
It doesn't show any properties

Playground Link:

Related Issues:

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Jul 8, 2019
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.7.0 milestone Jul 8, 2019
@mvestergaard
Copy link
Author

I've narrowed down the root cause of this being this definition in the react-select typings:

export type SelectComponentsProps = { [key in string]: any }; // <-- this

export interface Props<OptionType = { label: string; value: string }> extends SelectComponentsProps {

Is it expected behavior in this case, and if not, can you think of a workaround?

@mvestergaard
Copy link
Author

Managed to find a workaround by inferring the actual keys with this:

type KnownKeys<T> = { [K in keyof T]: string extends K ? never : number extends K ? never : K } extends { [_ in keyof T]: infer U } ? U : never;

export type SelectProps<T> = Pick<ReactSelectProps<T>, KnownKeys<ReactSelectProps<T>>>;

@evanpurkhiser
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

No branches or pull requests

4 participants