typescript-language-server / typescript-language-server

TypeScript & JavaScript Language Server

Home Page:https://www.npmjs.com/package/typescript-language-server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

problems with `interface` structure

rbd03 opened this issue · comments

for this code:

interface Array<T> {
  joinstr(): string;
}

Array.prototype.joinstr = function(): string {
  return this.join(" ");
}

let numarray = [23, 24, 12, 52, 23];
console.log(numarray.joinstr);

in vscode there are no errors whatsoever, but using typescript language server there are multiple diagnostics:

interface Array<T> { // 'Array' is declared but never used.
                     // 'T' is declared but its value is never read.
  joinstr(): string;
}

Array.prototype.joinstr = function(): string { // Property 'joinstr' does not exist on type 'any[]'.
  return this.join(" ");
}

let numarray = [23, 24, 12, 52, 23];
console.log(numarray.joinstr()); // Property 'joinstr' does not exist on type 'number[]'.

the code itself works as intended.

Cannot reproduce with "typescript-language-server": "4.3.3"
I get no errors.

Screenshot 2024-05-04 at 11 37 42

Here are mine initialization options that the server sends:

:: [11:39:02.208] --> LSP-typescript initialize (1): {'processId': 23335, 'clientInfo': {'name': 'Sublime Text LSP', 'version': '2.0.0'}, 'rootUri': 'file:///Users/predrag/Library/Application%20Support/Sublime%20Text/Packages/LSP', 'rootPath': '/Users/predrag/Library/Application Support/Sublime Text/Packages/LSP', 'workspaceFolders': [{'name': 'LSP', 'uri': 'file:///Users/predrag/Library/Application%20Support/Sublime%20Text/Packages/LSP'}], 'capabilities': {'general': {'regularExpressions': {'engine': 'ECMAScript'}, 'markdown': {'parser': 'Python-Markdown', 'version': '3.2.2'}}, 'textDocument': {'synchronization': {'dynamicRegistration': True, 'didSave': True, 'willSave': True, 'willSaveWaitUntil': True}, 'hover': {'dynamicRegistration': True, 'contentFormat': [<MarkupKind.Markdown: 'markdown'>, <MarkupKind.PlainText: 'plaintext'>]}, 'completion': {'dynamicRegistration': True, 'completionItem': {'snippetSupport': True, 'deprecatedSupport': True, 'documentationFormat': [<MarkupKind.Markdown: 'markdown'>, <MarkupKind.PlainText: 'plaintext'>], 'tagSupport': {'valueSet': [1]}, 'resolveSupport': {'properties': ['detail', 'documentation', 'additionalTextEdits']}, 'insertReplaceSupport': True, 'insertTextModeSupport': {'valueSet': [2]}, 'labelDetailsSupport': True}, 'completionItemKind': {'valueSet': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]}, 'insertTextMode': 2, 'completionList': {'itemDefaults': ['editRange', 'insertTextFormat', 'data']}}, 'signatureHelp': {'dynamicRegistration': True, 'contextSupport': True, 'signatureInformation': {'activeParameterSupport': True, 'documentationFormat': [<MarkupKind.Markdown: 'markdown'>, <MarkupKind.PlainText: 'plaintext'>], 'parameterInformation': {'labelOffsetSupport': True}}}, 'references': {'dynamicRegistration': True}, 'documentHighlight': {'dynamicRegistration': True}, 'documentSymbol': {'dynamicRegistration': True, 'hierarchicalDocumentSymbolSupport': True, 'symbolKind': {'valueSet': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]}, 'tagSupport': {'valueSet': [1]}}, 'documentLink': {'dynamicRegistration': True, 'tooltipSupport': True}, 'formatting': {'dynamicRegistration': True}, 'rangeFormatting': {'dynamicRegistration': True, 'rangesSupport': True}, 'declaration': {'dynamicRegistration': True, 'linkSupport': True}, 'definition': {'dynamicRegistration': True, 'linkSupport': True}, 'typeDefinition': {'dynamicRegistration': True, 'linkSupport': True}, 'implementation': {'dynamicRegistration': True, 'linkSupport': True}, 'codeAction': {'dynamicRegistration': True, 'codeActionLiteralSupport': {'codeActionKind': {'valueSet': [<CodeActionKind.QuickFix: 'quickfix'>, <CodeActionKind.Refactor: 'refactor'>, <CodeActionKind.RefactorExtract: 'refactor.extract'>, <CodeActionKind.RefactorInline: 'refactor.inline'>, <CodeActionKind.RefactorRewrite: 'refactor.rewrite'>, <CodeActionKind.SourceFixAll: 'source.fixAll'>, <CodeActionKind.SourceOrganizeImports: 'source.organizeImports'>]}}, 'dataSupport': True, 'isPreferredSupport': True, 'resolveSupport': {'properties': ['edit']}}, 'rename': {'dynamicRegistration': True, 'prepareSupport': True, 'prepareSupportDefaultBehavior': 1}, 'colorProvider': {'dynamicRegistration': True}, 'publishDiagnostics': {'relatedInformation': True, 'tagSupport': {'valueSet': [1, 2]}, 'versionSupport': True, 'codeDescriptionSupport': True, 'dataSupport': True}, 'diagnostic': {'dynamicRegistration': True, 'relatedDocumentSupport': True}, 'selectionRange': {'dynamicRegistration': True}, 'foldingRange': {'dynamicRegistration': True, 'foldingRangeKind': {'valueSet': [<FoldingRangeKind.Comment: 'comment'>, <FoldingRangeKind.Imports: 'imports'>, <FoldingRangeKind.Region: 'region'>]}}, 'codeLens': {'dynamicRegistration': True}, 'inlayHint': {'dynamicRegistration': True, 'resolveSupport': {'properties': ['textEdits', 'label.command']}}, 'semanticTokens': {'dynamicRegistration': True, 'requests': {'range': True, 'full': {'delta': True}}, 'tokenTypes': [<SemanticTokenTypes.Namespace: 'namespace'>, <SemanticTokenTypes.Type: 'type'>, <SemanticTokenTypes.Class: 'class'>, <SemanticTokenTypes.Enum: 'enum'>, <SemanticTokenTypes.Interface: 'interface'>, <SemanticTokenTypes.Struct: 'struct'>, <SemanticTokenTypes.TypeParameter: 'typeParameter'>, <SemanticTokenTypes.Parameter: 'parameter'>, <SemanticTokenTypes.Variable: 'variable'>, <SemanticTokenTypes.Property: 'property'>, <SemanticTokenTypes.EnumMember: 'enumMember'>, <SemanticTokenTypes.Event: 'event'>, <SemanticTokenTypes.Function: 'function'>, <SemanticTokenTypes.Method: 'method'>, <SemanticTokenTypes.Macro: 'macro'>, <SemanticTokenTypes.Keyword: 'keyword'>, <SemanticTokenTypes.Modifier: 'modifier'>, <SemanticTokenTypes.Comment: 'comment'>, <SemanticTokenTypes.String: 'string'>, <SemanticTokenTypes.Number: 'number'>, <SemanticTokenTypes.Regexp: 'regexp'>, <SemanticTokenTypes.Operator: 'operator'>, <SemanticTokenTypes.Decorator: 'decorator'>, 'member'], 'tokenModifiers': [<SemanticTokenModifiers.Declaration: 'declaration'>, <SemanticTokenModifiers.Definition: 'definition'>, <SemanticTokenModifiers.Readonly: 'readonly'>, <SemanticTokenModifiers.Static: 'static'>, <SemanticTokenModifiers.Deprecated: 'deprecated'>, <SemanticTokenModifiers.Abstract: 'abstract'>, <SemanticTokenModifiers.Async: 'async'>, <SemanticTokenModifiers.Modification: 'modification'>, <SemanticTokenModifiers.Documentation: 'documentation'>, <SemanticTokenModifiers.DefaultLibrary: 'defaultLibrary'>], 'formats': [<TokenFormat.Relative: 'relative'>], 'overlappingTokenSupport': False, 'multilineTokenSupport': True, 'augmentsSyntaxTokens': True}, 'callHierarchy': {'dynamicRegistration': True}, 'typeHierarchy': {'dynamicRegistration': True}}, 'workspace': {'applyEdit': True, 'didChangeConfiguration': {'dynamicRegistration': True}, 'executeCommand': {}, 'workspaceEdit': {'documentChanges': True, 'failureHandling': <FailureHandlingKind.Abort: 'abort'>}, 'workspaceFolders': True, 'symbol': {'dynamicRegistration': True, 'resolveSupport': {'properties': ['location.range']}, 'symbolKind': {'valueSet': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]}, 'tagSupport': {'valueSet': [1]}}, 'configuration': True, 'codeLens': {'refreshSupport': True}, 'inlayHint': {'refreshSupport': True}, 'semanticTokens': {'refreshSupport': True}, 'diagnostics': {'refreshSupport': True}, 'didChangeWatchedFiles': {'dynamicRegistration': True}}, 'window': {'showDocument': {'support': True}, 'showMessage': {'messageActionItem': {'additionalPropertiesSupport': True}}, 'workDoneProgress': True}}, 'initializationOptions': {'completionDisableFilterText': True, 'disableAutomaticTypingAcquisition': False, 'locale': 'en', 'maxTsServerMemory': 0, 'npmLocation': '', 'plugins': [], 'preferences': {'allowIncompleteCompletions': True, 'allowRenameOfImportPath': True, 'allowTextChangesInNewFiles': True, 'autoImportFileExcludePatterns': [], 'disableSuggestions': False, 'displayPartsForJSDoc': True, 'excludeLibrarySymbolsInNavTo': True, 'generateReturnInDocTemplate': True, 'importModuleSpecifierEnding': 'auto', 'importModuleSpecifierPreference': 'shortest', 'includeAutomaticOptionalChainCompletions': True, 'includeCompletionsForImportStatements': True, 'includeCompletionsForModuleExports': True, 'includeCompletionsWithClassMemberSnippets': True, 'includeCompletionsWithInsertText': True, 'includeCompletionsWithObjectLiteralMethodSnippets': True, 'includeCompletionsWithSnippetText': True, 'includePackageJsonAutoImports': 'auto', 'interactiveInlayHints': True, 'jsxAttributeCompletionStyle': 'auto', 'lazyConfiguredProjectsFromExternalProject': False, 'organizeImportsAccentCollation': True, 'organizeImportsCaseFirst': False, 'organizeImportsCollation': 'ordinal', 'organizeImportsCollationLocale': 'en', 'organizeImportsIgnoreCase': 'auto', 'organizeImportsNumericCollation': False, 'providePrefixAndSuffixTextForRename': True, 'provideRefactorNotApplicableReason': True, 'quotePreference': 'auto', 'useLabelDetailsInCompletionEntries': True}, 'tsserver': {'fallbackPath': '', 'logDirectory': '', 'logVerbosity': 'off', 'path': '', 'trace': 'off', 'useSyntaxServer': 'auto'}}}
:: [11:39:02.267] <-  LSP-typescript window/logMessage: {'type': 3, 'message': 'Using Typescript version (bundled) 5.4.5 from path "/Users/predrag/Library/Caches/Sublime Text/Package Storage/LSP-typescript/18.18.1/typescript-language-server/node_modules/typescript/lib/tsserver.js"'}

It could be that your initalizartionoptions are a bit different that mine,
or you have a tsconfig.json that causes some of these errors.

But I can only assume.
If you can create a minimal repository that can reproduce the issue, I could try.

hm... for me strict and strictNullChecks is true, could that be why? nevermind just tested, it doesn't make a difference.

seems like a one-off incident, will close this issue for now. thanks for the help!