Skip to content
This repository has been archived by the owner on Feb 2, 2022. It is now read-only.

Inconsistent token type when interface require optional properties #14

Open
aeschli opened this issue May 7, 2020 · 1 comment
Open

Comments

@aeschli
Copy link
Owner

aeschli commented May 7, 2020

See microsoft/vscode#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
Copy link
Owner Author

aeschli commented May 7, 2020

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.

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant