microsoft / microsoft/TypeScript

isArray type guards still causing issues in latest nightly build

Open
#42,768 8 comments 0 reactions 1 assignee View on GitHub

@orta is already working on this.

Since Feb 12, 2021.

Needs Investigation Rescheduled
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

Bug Report

🔎 Search Terms
  • isArray
🕗 Version & Regression Information

Tested in 4.3.0-dev.20210211 which

💻 Code

In the VS Code codebase, we are still seeing the isArray type guards causing problems with the latest TS 4.3 nightly build.

Here's an example from this file

The type of DocumentSelector is string | vscode.DocumentFilter | readonly (string | vscode.DocumentFilter)[]

	export function from(selector: vscode.DocumentSelector | undefined): languageSelector.LanguageSelector | undefined {
		if (!selector) {
			return undefined;
		} else if (Array.isArray(selector)) {
			return <languageSelector.LanguageSelector>selector.map(from);
		} else if (typeof selector === 'string') {
			return selector;
		} else {
			return <languageSelector.LanguageFilter>{
				language: selector.language,
				scheme: selector.scheme,
				pattern: typeof selector.pattern === 'undefined' ? undefined : GlobPattern.from(selector.pattern),
				exclusive: selector.exclusive
			};
		}
	}

The error in the else block on the line language: selector.language:

[watch-client    ] [13:45:27] Error: /Users/matb/projects/vscode/src/vs/workbench/api/common/extHostTypeConverters.ts(1284,24): Property 'language' does not exist on type 'DocumentFilter | readonly (string | DocumentFilter)[]'.
[watch-client    ]   Property 'language' does not exist on type 'readonly (string | DocumentFilter)[]'.

These errors did not show up with typescript@4.2.0-dev.20201207.

Here are the other errors:

[watch-client    ] [13:45:27] Error: /Users/matb/projects/vscode/src/vs/workbench/services/extensions/common/abstractExtensionService.ts(545,58): Argument of type 'ILocalization[] | IAuthenticationContribution[] | IDebugger[] | { [location: string]: IView[]; } | ISnippet[] | IConfiguration | ... 12 more ... | undefined' is not assignable to parameter of type 'T'.
[watch-client    ]   'T' could be instantiated with an arbitrary type which could be unrelated to 'ILocalization[] | IAuthenticationContribution[] | IDebugger[] | { [location: string]: IView[]; } | ISnippet[] | IConfiguration | ... 12 more ... | undefined'.
[watch-client    ]     Type 'undefined' is not assignable to type 'T'.
[watch-client    ]       'T' could be instantiated with an arbitrary type which could be unrelated to 'undefined'.
[watch-client    ] [13:45:27] Error: /Users/matb/projects/vscode/src/vs/workbench/services/extensions/common/abstractExtensionService.ts(700,6): Type 'ILocalization[] | IAuthenticationContribution[] | IDebugger[] | { [location: string]: IView[]; } | ISnippet[] | IConfiguration | ... 12 more ... | undefined' is not assignable to type 'T'.
[watch-client    ]   'T' could be instantiated with an arbitrary type which could be unrelated to 'ILocalization[] | IAuthenticationContribution[] | IDebugger[] | { [location: string]: IView[]; } | ISnippet[] | IConfiguration | ... 12 more ... | undefined'.
[watch-client    ]     Type 'undefined' is not assignable to type 'T'.
[watch-client    ]       'T' could be instantiated with an arbitrary type which could be unrelated to 'undefined'.
[watch-client    ] [13:45:27] Error: /Users/matb/projects/vscode/src/vs/base/browser/ui/dropdown/dropdownActionViewItem.ts(175,99): Property 'getActions' does not exist on type 'readonly IAction[] | IActionProvider'.
[watch-client    ]   Property 'getActions' does not exist on type 'readonly IAction[]'.
[watch-client    ] [13:45:27] Error: /Users/matb/projects/vscode/src/vs/workbench/api/common/extHostTypeConverters.ts(1284,24): Property 'language' does not exist on type 'DocumentFilter | readonly (string | DocumentFilter)[]'.
[watch-client    ]   Property 'language' does not exist on type 'readonly (string | DocumentFilter)[]'.
[watch-client    ] [13:45:27] Error: /Users/matb/projects/vscode/src/vs/workbench/api/common/extHostTypeConverters.ts(1285,22): Property 'scheme' does not exist on type 'DocumentFilter | readonly (string | DocumentFilter)[]'.
[watch-client    ]   Property 'scheme' does not exist on type 'readonly (string | DocumentFilter)[]'.
[watch-client    ] [13:45:27] Error: /Users/matb/projects/vscode/src/vs/workbench/api/common/extHostTypeConverters.ts(1286,30): Property 'pattern' does not exist on type 'DocumentFilter | readonly (string | DocumentFilter)[]'.
[watch-client    ]   Property 'pattern' does not exist on type 'readonly (string | DocumentFilter)[]'.
[watch-client    ] [13:45:27] Error: /Users/matb/projects/vscode/src/vs/workbench/api/common/extHostTypeConverters.ts(1286,94): Property 'pattern' does not exist on type 'DocumentFilter | readonly (string | DocumentFilter)[]'.
[watch-client    ]   Property 'pattern' does not exist on type 'readonly (string | DocumentFilter)[]'.
[watch-client    ] [13:45:27] Error: /Users/matb/projects/vscode/src/vs/workbench/api/common/extHostTypeConverters.ts(1287,25): Property 'exclusive' does not exist on type 'DocumentFilter | readonly (string | DocumentFilter)[]'.
[watch-client    ]   Property 'exclusive' does not exist on type 'readonly (string | DocumentFilter)[]'.
[watch-client    ] [13:45:27] Error: /Users/matb/projects/vscode/src/vs/workbench/api/common/extHost.api.impl.ts(201,26): Property 'scheme' does not exist on type 'DocumentFilter | readonly (string | DocumentFilter)[]'.
[watch-client    ]   Property 'scheme' does not exist on type 'readonly (string | DocumentFilter)[]'.
[watch-client    ] [13:45:27] Error: /Users/matb/projects/vscode/src/vs/workbench/api/common/extHost.api.impl.ts(204,58): Property 'exclusive' does not exist on type 'DocumentFilter | readonly (string | DocumentFilter)[]'.
[watch-client    ]   Property 'exclusive' does not exist on type 'readonly (string | DocumentFilter)[]'.
[watch-client    ] [13:45:27] Error: /Users/matb/projects/vscode/src/vs/editor/common/modes/languageSelector.ts(58,11): Property 'language' does not exist on type 'LanguageFilter | readonly (string | LanguageFilter)[]'.
[watch-client    ] [13:45:27] Error: /Users/matb/projects/vscode/src/vs/editor/common/modes/languageSelector.ts(58,21): Property 'pattern' does not exist on type 'LanguageFilter | readonly (string | LanguageFilter)[]'.
[watch-client    ] [13:45:27] Error: /Users/matb/projects/vscode/src/vs/editor/common/modes/languageSelector.ts(58,30): Property 'scheme' does not exist on type 'LanguageFilter | readonly (string | LanguageFilter)[]'.
[watch-client    ] [13:45:27] Error: /Users/matb/projects/vscode/src/vs/editor/common/modes/languageSelector.ts(58,38): Property 'hasAccessToAllModels' does not exist on type 'LanguageFilter | readonly (string | LanguageFilter)[]'.
[watch-client    ] [13:45:27] Error: /Users/matb/projects/vscode/src/vs/editor/common/modes/languageFeatureRegistry.ts(28,21): Property 'exclusive' does not exist on type 'LanguageFilter | readonly (string | LanguageFilter)[]'.
[watch-client    ]   Property 'exclusive' does not exist on type 'readonly (string | LanguageFilter)[]'.

@orta @RyanCavanaugh I believed that https://github.com/microsoft/TypeScript/pull/41851 was supposed to fix these issues. Can you please take a look at our errors and me know if we need to change anything on the VS Code side or if these are unexpected errors

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.