Handle unresolved baseType when trying to get completions for static member (#39731)

* Handle unresolved baseType when trying to get completions for static member
Fixes  #38067

* Update src/services/completions.ts

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>

* correct the condition

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
This commit is contained in:
Sheetal Nandi 2020-07-24 16:37:28 -07:00 committed by GitHub
parent c5d21e7987
commit 48e58f44db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 1 deletions

View File

@ -2012,7 +2012,9 @@ namespace ts.Completions {
// List of property symbols of base type that are not private and already implemented
const baseSymbols = flatMap(getAllSuperTypeNodes(decl), baseTypeNode => {
const type = typeChecker.getTypeAtLocation(baseTypeNode);
return type && typeChecker.getPropertiesOfType(classElementModifierFlags & ModifierFlags.Static ? typeChecker.getTypeOfSymbolAtLocation(type.symbol, decl) : type);
return classElementModifierFlags & ModifierFlags.Static ?
type?.symbol && typeChecker.getPropertiesOfType(typeChecker.getTypeOfSymbolAtLocation(type.symbol, decl)) :
type && typeChecker.getPropertiesOfType(type);
});
symbols = filterClassMembersList(baseSymbols, decl.members, classElementModifierFlags);
}

View File

@ -0,0 +1,35 @@
/// <reference path="fourslash.ts" />
// @Filename: /node_modules/@types/react/index.d.ts
//// export = React;
//// export as namespace React;
//// declare namespace React {
//// function createElement(): any;
//// interface Component<P = {}, S = {}, SS = any> { }
//// class Component<P, S> {
//// static contextType?: any;
//// context: any;
//// constructor(props: Readonly<P>);
//// setState<K extends keyof S>(
//// state: ((prevState: Readonly<S>, props: Readonly<P>) => (Pick<S, K> | S | null)) | (Pick<S, K> | S | null),
//// callback?: () => void
//// ): void;
//// }
//// }
// @Filename: /a.ts
//// import React from 'react'
//// class Slider extends React.Component {
//// static defau/**/ltProps = {
//// onMouseDown: () => { },
//// onMouseUp: () => { },
//// unit: 'px',
//// }
//// handleChange = () => 10;
//// }
verify.completions({
marker: "",
isNewIdentifierLocation: true,
exact: completion.classElementKeywords,
});