typescript-vscode-sh-plugin icon indicating copy to clipboard operation
typescript-vscode-sh-plugin copied to clipboard

Inconsistent token type when interface require optional properties

Open aeschli opened this issue 4 years ago • 1 comments

See https://github.com/microsoft/vscode/issues/95867

Reproduce recording: semantic-highlighting-vscode-issue

Source:

import * as React from 'react'

type SomeProps = {
    a: number
}

interface A <P = {}> {
    (props: P, context?: any): React.ReactElement;
}

interface AA <P = {}> {
    (props: P, context?: any): React.ReactElement;
    propTypes?: any;
    contextTypes?: any;
    defaultProps?: Partial<P>;
    displayName?: string;
}

// correct
const Layout1: A<SomeProps> = (props: SomeProps) => {
    return <div>{props}</div>
}

// incorrect semantic identification
const Layout2: AA<SomeProps> = (props: SomeProps) => {
    return <div>{props}</div>
}

export { Layout1, Layout2 };

Does this issue occur when all extensions are disabled?: No

aeschli avatar May 07 '20 12:05 aeschli

With

interface AA <P = {}> {
    (props: P, context?: any): React.ReactElement;
    propTypes?: any;
    contextTypes?: any;
    defaultProps?: Partial<P>;
    displayName?: string;
}

Because the type is callable and has properties, it is a guess what the main purpose of the type is. We currently have the rule that we only call something a function if it has no properties as well, But when it is used as a function, it will be colored as a function.

aeschli avatar May 07 '20 12:05 aeschli