typescript-vscode-sh-plugin
typescript-vscode-sh-plugin copied to clipboard
Inconsistent token type when interface require optional properties
See https://github.com/microsoft/vscode/issues/95867
Reproduce recording:
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
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.