microsoft / microsoft/TypeScript

isArray type guards still causing issues in latest nightly build

Aperta
#42,768 8 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@orta ci sta già lavorando.

Dal 12/2/2021.

Needs Investigation Rescheduled
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.