Skip to content

TypeScript 3.5 compile errors in the VS Code codebase #31380

Description

@mjbvz

TypeScript Version: 3.5.0-dev.20190512

Repo
Build VS Code with TypeScript@next:

git clone https://github.com/microsoft/vscode.git
cd vscode
yarn add typescript@next
yarn run watch

Potential issues
There are 68 compile errors on TS@next, compared to zero when compiling with TS@3.4.5:

[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/welcome/walkThrough/browser/editor/editorWalkThrough.ts(53,9): Property 'deserialize' in type 'EditorWalkThroughInputFactory' is not assignable to the same property in base type 'IEditorInputFactory'.
  Type '(instantiationService: IInstantiationService, serializedEditorInput: string) => WalkThroughInput' is not assignable to type '(instantiationService: IInstantiationService, serializedEditorInput: string) => EditorInput | undefined'.
    Type 'WalkThroughInput' is not assignable to type 'EditorInput'.
      Types of property 'getTelemetryDescriptor' are incompatible.
        Type '() => object' is not assignable to type '() => { [key: string]: unknown; }'.
          Type 'object' is not assignable to type '{ [key: string]: unknown; }'.
            Index signature is missing in type '{}'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/welcome/walkThrough/common/walkThroughInput.ts(83,2): Property 'getTelemetryDescriptor' in type 'WalkThroughInput' is not assignable to the same property in base type 'EditorInput'.
  Type '() => object' is not assignable to type '() => { [key: string]: unknown; }'.
    Type 'object' is not assignable to type '{ [key: string]: unknown; }'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/welcome/walkThrough/browser/walkThroughPart.ts(254,2): Property 'setInput' in type 'WalkThroughPart' is not assignable to the same property in base type 'BaseEditor'.
  Type '(input: WalkThroughInput, options: EditorOptions, token: CancellationToken) => Promise<void>' is not assignable to type '(input: EditorInput, options: EditorOptions | null, token: CancellationToken) => Promise<void>'.
    Types of parameters 'input' and 'input' are incompatible.
      Type 'EditorInput' is missing the following properties from type 'WalkThroughInput': disposables, promise, maxTopScroll, maxBottomScroll, and 5 more.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/welcome/walkThrough/browser/walkThroughPart.ts(262,25): Argument of type 'WalkThroughInput' is not assignable to parameter of type 'EditorInput'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/welcome/walkThrough/browser/walkThroughPart.ts(266,10): Parameter 'model' implicitly has an 'any' type.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/welcome/walkThrough/browser/walkThroughPart.ts(298,29): Parameter 'snippet' implicitly has an 'any' type.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/welcome/walkThrough/browser/walkThroughPart.ts(298,38): Parameter 'i' implicitly has an 'any' type.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/welcome/walkThrough/browser/walkThroughPart.ts(481,51): Argument of type 'WalkThroughInput' is not assignable to parameter of type 'EditorInput'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/welcome/walkThrough/browser/walkThroughPart.ts(492,65): Argument of type 'WalkThroughInput' is not assignable to parameter of type 'EditorInput'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/welcome/walkThrough/browser/walkThrough.contribution.ts(24,3): Argument of type 'typeof WalkThroughPart' is not assignable to parameter of type 'IConstructorSignature0<BaseEditor>'.
  Type 'WalkThroughPart' is not assignable to type 'BaseEditor'.
    Types of property 'setInput' are incompatible.
      Type '(input: WalkThroughInput, options: EditorOptions, token: CancellationToken) => Promise<void>' is not assignable to type '(input: EditorInput, options: EditorOptions | null, token: CancellationToken) => Promise<void>'.
        Types of parameters 'input' and 'input' are incompatible.
          Type 'EditorInput' is not assignable to type 'WalkThroughInput'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/welcome/walkThrough/browser/walkThrough.contribution.ts(35,147): Argument of type 'typeof EditorWalkThroughInputFactory' is not assignable to parameter of type 'IConstructorSignature0<IEditorInputFactory>'.
  Type 'EditorWalkThroughInputFactory' is not assignable to type 'IEditorInputFactory'.
    Types of property 'deserialize' are incompatible.
      Type '(instantiationService: IInstantiationService, serializedEditorInput: string) => WalkThroughInput' is not assignable to type '(instantiationService: IInstantiationService, serializedEditorInput: string) => EditorInput | undefined'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/welcome/page/browser/welcomePage.ts(610,9): Property 'deserialize' in type 'WelcomeInputFactory' is not assignable to the same property in base type 'IEditorInputFactory'.
  Type '(instantiationService: IInstantiationService, serializedEditorInput: string) => WalkThroughInput' is not assignable to type '(instantiationService: IInstantiationService, serializedEditorInput: string) => EditorInput | undefined'.
    Type 'WalkThroughInput' is not assignable to type 'EditorInput'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/welcome/page/browser/welcomePage.contribution.ts(45,132): Argument of type 'typeof WelcomeInputFactory' is not assignable to parameter of type 'IConstructorSignature0<IEditorInputFactory>'.
  Type 'WelcomeInputFactory' is not assignable to type 'IEditorInputFactory'.
    Types of property 'deserialize' are incompatible.
      Type '(instantiationService: IInstantiationService, serializedEditorInput: string) => WalkThroughInput' is not assignable to type '(instantiationService: IInstantiationService, serializedEditorInput: string) => EditorInput | undefined'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/services/themes/common/fileIconThemeData.ts(121,7): Type 'any' is not assignable to type 'never'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/services/themes/common/colorThemeData.ts(254,7): Type 'any' is not assignable to type 'never'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/services/keybinding/common/keybindingEditing.ts(213,17): Object is of type 'unknown'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/services/extensions/node/extensionPoints.ts(292,16): Property 'hasOwnProperty' does not exist on type 'T'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/services/editor/browser/editorService.ts(510,4): Type 'SideBySideEditorInput' is not assignable to type 'EditorInput'.
  Types of property 'getTelemetryDescriptor' are incompatible.
    Type '() => object' is not assignable to type '() => { [key: string]: unknown; }'.
      Type 'object' is not assignable to type '{ [key: string]: unknown; }'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/services/editor/browser/editorService.ts(525,4): Type 'DiffEditorInput' is not assignable to type 'EditorInput'.
  Types of property 'getTelemetryDescriptor' are incompatible.
    Type '() => object' is not assignable to type '() => { [key: string]: unknown; }'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/test/common/editor/editorGroups.test.ts(213,31): Argument of type 'DiffEditorInput' is not assignable to parameter of type 'EditorInput'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/test/common/editor/editorGroups.test.ts(214,31): Argument of type 'DiffEditorInput' is not assignable to parameter of type 'EditorInput'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/tasks/common/problemMatcher.ts(268,4): Type 'string' is not assignable to type 'undefined'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/tasks/common/problemMatcher.ts(280,5): Type 'string' is not assignable to type 'undefined'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/tasks/common/problemMatcher.ts(899,5): Type 'number' is not assignable to type 'undefined & RegExp'.
  Type 'number' is not assignable to type 'undefined'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/search/browser/searchView.ts(647,66): Argument of type 'ITreeContextMenuEvent<FileMatch | Match | BaseFolderMatch | FolderMatch | null>' is not assignable to parameter of type 'ITreeContextMenuEvent<RenderableMatch>'.
  Type 'FileMatch | Match | BaseFolderMatch | FolderMatch | null' is not assignable to type 'RenderableMatch'.
    Type 'null' is not assignable to type 'RenderableMatch'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/preferences/electron-browser/preferences.contribution.ts(49,3): Argument of type 'typeof PreferencesEditor' is not assignable to parameter of type 'IConstructorSignature0<BaseEditor>'.
  Type 'PreferencesEditor' is not assignable to type 'BaseEditor'.
    Types of property 'setInput' are incompatible.
      Type '(newInput: PreferencesEditorInput, options: SettingsEditorOptions, token: CancellationToken) => Promise<void>' is not assignable to type '(input: EditorInput, options: EditorOptions | null, token: CancellationToken) => Promise<void>'.
        Types of parameters 'newInput' and 'input' are incompatible.
          Type 'EditorInput' is missing the following properties from type 'PreferencesEditorInput': name, description, _details, _master, and 3 more.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/preferences/electron-browser/preferences.contribution.ts(134,5): Type 'PreferencesEditorInput' is not assignable to type 'EditorInput'.
  Types of property 'getTelemetryDescriptor' are incompatible.
    Type '() => object' is not assignable to type '() => { [key: string]: unknown; }'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/preferences/browser/preferencesEditor.ts(157,2): Property 'setInput' in type 'PreferencesEditor' is not assignable to the same property in base type 'BaseEditor'.
  Type '(newInput: PreferencesEditorInput, options: SettingsEditorOptions, token: CancellationToken) => Promise<void>' is not assignable to type '(input: EditorInput, options: EditorOptions | null, token: CancellationToken) => Promise<void>'.
    Types of parameters 'newInput' and 'input' are incompatible.
      Type 'EditorInput' is not assignable to type 'PreferencesEditorInput'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/preferences/browser/preferencesEditor.ts(164,25): Argument of type 'PreferencesEditorInput' is not assignable to parameter of type 'EditorInput'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/output/browser/outputPanel.ts(100,8): Object is of type 'unknown'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/output/browser/outputPanel.ts(103,29): Object is of type 'unknown'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/output/browser/outputPanel.ts(104,24): Object is of type 'unknown'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/extensions/electron-browser/extensionTipsService.ts(975,83): Object is of type 'unknown'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/extensions/electron-browser/extensionTipsService.ts(975,121): Object is of type 'unknown'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/experiments/node/experimentService.ts(181,36): Object is of type 'unknown'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/experiments/node/experimentService.ts(181,61): Object is of type 'unknown'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/contrib/debug/electron-browser/debugService.ts(746,8): Argument of type 'unknown' is not assignable to parameter of type 'ITaskSummary | Thenable<ITaskSummary | null> | null | undefined'.
  Type 'unknown' is not assignable to type 'Thenable<ITaskSummary | null>'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/browser/parts/notifications/notificationsList.ts(222,4): Type 'string | null' is not assignable to type 'string'.
  Type 'null' is not assignable to type 'string'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/browser/parts/editor/textDiffEditor.ts(164,48): Argument of type 'string | null' is not assignable to parameter of type 'string'.
  Type 'null' is not assignable to type 'string'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/browser/parts/editor/tabsTitleControl.ts(713,4): Type 'null' is not assignable to type 'string'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/browser/parts/editor/tabsTitleControl.ts(714,4): Type 'null' is not assignable to type 'string'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/browser/parts/editor/tabsTitleControl.ts(715,4): Type 'string | null' is not assignable to type 'string'.
  Type 'null' is not assignable to type 'string'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/browser/parts/editor/tabsTitleControl.ts(716,4): Type 'null' is not assignable to type 'string'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/browser/parts/editor/tabsTitleControl.ts(853,3): Type 'string | null' is not assignable to type 'string'.
  Type 'null' is not assignable to type 'string'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/browser/parts/editor/sideBySideEditor.ts(96,2): Property 'setInput' in type 'SideBySideEditor' is not assignable to the same property in base type 'BaseEditor'.
  Type '(newInput: SideBySideEditorInput, options: EditorOptions, token: CancellationToken) => Promise<void>' is not assignable to type '(input: EditorInput, options: EditorOptions | null, token: CancellationToken) => Promise<void>'.
    Types of parameters 'newInput' and 'input' are incompatible.
      Type 'EditorInput' is missing the following properties from type 'SideBySideEditorInput': name, description, _details, _master, and 3 more.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/browser/parts/editor/sideBySideEditor.ts(98,25): Argument of type 'SideBySideEditorInput' is not assignable to parameter of type 'EditorInput'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/browser/parts/editor/editorStatus.ts(1022,48): Object is of type 'unknown'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/browser/parts/editor/editorDropTarget.ts(91,3): Type 'string | null' is not assignable to type 'string'.
  Type 'null' is not assignable to type 'string'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/browser/parts/editor/editorDropTarget.ts(92,3): Type '"-2px" | null' is not assignable to type 'string'.
  Type 'null' is not assignable to type 'string'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/browser/parts/editor/editorDropTarget.ts(93,3): Type '"dashed" | null' is not assignable to type 'string'.
  Type 'null' is not assignable to type 'string'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/browser/parts/editor/editorDropTarget.ts(94,3): Type '"2px" | null' is not assignable to type 'string'.
  Type 'null' is not assignable to type 'string'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/browser/parts/editor/editor.contribution.ts(84,3): Argument of type 'typeof BinaryResourceDiffEditor' is not assignable to parameter of type 'IConstructorSignature0<BaseEditor>'.
  Type 'BinaryResourceDiffEditor' is not assignable to type 'BaseEditor'.
    Types of property 'setInput' are incompatible.
      Type '(newInput: SideBySideEditorInput, options: EditorOptions, token: CancellationToken) => Promise<void>' is not assignable to type '(input: EditorInput, options: EditorOptions | null, token: CancellationToken) => Promise<void>'.
        Types of parameters 'newInput' and 'input' are incompatible.
          Type 'EditorInput' is not assignable to type 'SideBySideEditorInput'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/browser/parts/editor/editor.contribution.ts(95,3): Argument of type 'typeof SideBySideEditor' is not assignable to parameter of type 'IConstructorSignature0<BaseEditor>'.
  Type 'SideBySideEditor' is not assignable to type 'BaseEditor'.
    Types of property 'setInput' are incompatible.
      Type '(newInput: SideBySideEditorInput, options: EditorOptions, token: CancellationToken) => Promise<void>' is not assignable to type '(input: EditorInput, options: EditorOptions | null, token: CancellationToken) => Promise<void>'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/browser/parts/editor/editor.contribution.ts(148,52): Types of property 'language' are incompatible.
  Type 'string | null' is not assignable to type 'string | undefined'.
    Type 'null' is not assignable to type 'string | undefined'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/browser/parts/editor/editor.contribution.ts(209,5): Type 'SideBySideEditorInput' is not assignable to type 'EditorInput'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/browser/parts/editor/breadcrumbsPicker.ts(391,10): Conversion of type 'WorkbenchAsyncDataTree<URI | IWorkspace | IWorkspaceFolder | IFileStat, URI | IWorkspace | IWorkspaceFolder | IFileStat, [number, number, number]>' to type 'WorkbenchAsyncDataTree<BreadcrumbElement, any, [number, number, number]>' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
  Type 'URI | IWorkspace | IWorkspaceFolder | IFileStat' is not comparable to type 'BreadcrumbElement'.
    Type 'IFileStat' is not comparable to type 'BreadcrumbElement'.
      Type 'IFileStat' is missing the following properties from type 'OutlineElement': marker, id, parent, symbol, and 2 more.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/browser/parts/activitybar/activitybarPart.ts(211,3): Type '"border-box" | null' is not assignable to type 'string'.
  Type 'null' is not assignable to type 'string'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/base/browser/ui/selectBox/selectBoxCustom.ts(399,4): Type 'string | null' is not assignable to type 'string'.
  Type 'null' is not assignable to type 'string'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/platform/instantiation/common/instantiationService.ts(226,13): Object is of type 'unknown'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/platform/instantiation/common/instantiationService.ts(229,6): Object is of type 'unknown'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/editor/contrib/colorPicker/colorDetector.ts(81,26): Object is of type 'unknown'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/base/test/node/config.test.ts(27,28): Argument of type 'unknown' is not assignable to parameter of type 'object'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/common/editor.ts(569,2): Property 'getTelemetryDescriptor' in type 'SideBySideEditorInput' is not assignable to the same property in base type 'EditorInput'.
  Type '() => object' is not assignable to type '() => { [key: string]: unknown; }'.
    Type 'object' is not assignable to type '{ [key: string]: unknown; }'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/browser/dnd.ts(84,22): Types of property 'viewState' are incompatible.
  Type 'ICodeEditorViewState | IDiffEditorViewState | null' is not assignable to type 'ICodeEditorViewState | IDiffEditorViewState | undefined'.
    Type 'null' is not assignable to type 'ICodeEditorViewState | IDiffEditorViewState | undefined'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/base/common/parsers.ts(83,15): Argument of type 'T' is not assignable to parameter of type 'object'.
[15:39:42] Error: /Users/matb/projects/vscode/src/vs/base/common/objects.ts(17,14): Argument of type 'T' is not assignable to parameter of type 'object'.
[15:39:42] Error: /Users/matb/projects/vscode/extensions/typescript-language-features/src/utils/surveyor.ts(107,27): Object is of type 'unknown'.
[15:39:42] Error: /Users/matb/projects/vscode/extensions/typescript-language-features/src/utils/surveyor.ts(107,41): Object is of type 'unknown'.

Some of these seem related to #30637 but other ones seem suspect (or should be noted in the breaking changes)

Activity

  1. mjbvz commented on May 13, 2019

    @mjbvz
    Author

    Specific issues that seem like breaking changes:

    1. A few style properties in dom.d.ts are no longer nullable:

      [15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/browser/parts/editor/editorDropTarget.ts(91,3): Type 'string | null' is not assignable to type 'string'.
      
    2. TS 3.5 regression casting object to { [key: string]: unknown }; #31381

    3. Issues around switch statement for keys that write to an object in the case body (still trying to put together a minimal repo for this one)

      [15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/services/themes/common/fileIconThemeData.ts(121,7): Type 'any' is not assignable to type 'never'.
      
    4. TS 3.5 new error when using keyof with assignment to copy property #31382

  2. mjbvz commented on May 14, 2019

    @mjbvz
    Author

    I fixed many of these errors in microsoft/vscode@fd1ac75

  3. RyanCavanaugh commented on May 14, 2019

    @RyanCavanaugh
    Member

    microsoft/vscode@fd1ac75#diff-fed321a94e979ed6f2aaaf1001dbac36L17

    Caused by #27089. We might consider reverting the lib change because this code is manifestly correct, but our lack of ability to narrow T to Objectish<T> from the typeof check at the top of the function means we incorrectly reject the call.

  4. RyanCavanaugh commented on May 14, 2019

    @RyanCavanaugh
    Member

    microsoft/vscode@fd1ac75#diff-4414fa1e065d93e77c72eec3db97c187L105

    We previously inferred count to be {} | undefined, but now infer it to be unknown. The {} | undefined type was "better" because it could narrow away undefined in the !count || expression, then {} could be "safely" coerced with +count.

    Again, this is a case of manifestly correct code where we need type facts here to express the fact that undefined and null were removed from the type by the truthiness check.

    There's a case to be made that our rules around unary + are inconsistent enough to be useless. +{} is really not any more or less suspect than +undefined and maybe we should just allow it for everything, same as "" + unknown

  5. RyanCavanaugh commented on May 14, 2019

    @RyanCavanaugh
    Member

    microsoft/vscode@fd1ac75#diff-11b5b53dd82e487bffdf3b724fad9d83L82

    We prevented a hypothetical call of merge(0, 0, false) which would throw under ES5 (#27089)

  6. weswigham commented on May 14, 2019

    @weswigham
    Member

    Again, this is a case of manifestly correct code where we need type facts here to express the fact that undefined and null were removed from the type by the truthiness check.

    unknown & not undefined -> not undefined ❤️

    Type facts as they exist today can only remove types from a union, not "add negated types to an intersection", so it's moreso a shortcoming in the type facts system as it exists than some specific fact being missing. Simply put: The type to narrow to in the case where x !== undefined simply cannot be expressed today. You could get real close by converting unknown into {} | undefined | null and narrowing that, but {} carries some object-like baggage that could cause interesting behavior down the line.

  7. RyanCavanaugh commented on May 14, 2019

    @RyanCavanaugh
    Member

    microsoft/vscode@fd1ac75#diff-6c07482b4bc75dfd16bc0d2239065809R162

    Context: VS Code has suppressImplicitAnyIndexErrors enabled.

    The relevant calling code looks like this (simplified):

    return asJson(context).then(result => {
    	return result && result['experiments'];
    });

    Most other uses of asJson supply the type parameter to provide the expected JSON shape. The intent, I guess, is to fall back to something like any when that's not provided. Going back to unknown is really quite bad here because result's type is supposed to meaningfully include | null.

    It's not clear how to proceed here since the code was quite unsafe to begin with. We should get a time machine and ban uninferrable type parameters.

  8. RyanCavanaugh commented on May 14, 2019

    @RyanCavanaugh
    Member

    microsoft/vscode@fd1ac75#diff-1e9db0aff31fe7167a26aef6c4176a19R23

    The failing example looks like this:

    		let watcher = new ConfigWatcher<{}>(testFile);
    
    		let config = watcher.getConfig();
    		assert.ok(config);
    		assert.equal(Object.keys(config), 0);

    This is a hairy variant of the foo && Object.keys(foo) problem since they're using assert.ok to validate the truthiness of config. However, the error is entirely correct - if testFile's contents were 5, this would throw under ES5 as specified in the target. ConfigWatcher<T> should have a constraint.

  9. RyanCavanaugh commented on May 14, 2019

    @RyanCavanaugh
    Member

    microsoft/vscode@fd1ac75#diff-641fa4cc338f106854e4b4a33964acbdR84

    This is an extremely real error.

    Consider these three assignments:

    						const k1: IDraggedEditor = {
    							resource: URI.parse(draggedEditor.resource),
    							backupResource: draggedEditor.backupResource ? URI.parse(draggedEditor.backupResource) : undefined,
    							viewState: draggedEditor.viewState,
    							isExternal: false
    						};
    
    						const k2: IDraggedResource = {
    							resource: URI.parse(draggedEditor.resource),
    							backupResource: draggedEditor.backupResource ? URI.parse(draggedEditor.backupResource) : undefined,
    							viewState: draggedEditor.viewState,
    							isExternal: false
    						};
    
    						const k3: IDraggedEditor | IDraggedResource = {
    							resource: URI.parse(draggedEditor.resource),
    							backupResource: draggedEditor.backupResource ? URI.parse(draggedEditor.backupResource) : undefined,
    							viewState: draggedEditor.viewState,
    							isExternal: false
    						};
    

    k3 should not be a legal initialization unless at least one of k1 and k2 are, but both of those are also errors. The provided object literal is not a match for either object -- backupResource is extraneous in IDraggedEditor, and viewState has the wrong type in IDraggedResource.

  10. RyanCavanaugh commented on May 14, 2019

    @RyanCavanaugh
    Member

    microsoft/vscode@fd1ac75#diff-b7604f54db2a2f61d2bf5af1fcc5047fL391

    I can't tell what's going on here; this doesn't error locally for me. The type is extremely complex.

  11. RyanCavanaugh commented on May 14, 2019

    @RyanCavanaugh
    Member

    Re #31380 (comment), why can't the types be narrowed correctly?

    Let's take that discussion to the PR please

  12. RyanCavanaugh commented on May 14, 2019

    @RyanCavanaugh
    Member

    microsoft/vscode@fd1ac75#diff-1ba53e60093143b29593e77afffaacb6L1036

    microsoft/vscode@fd1ac75#diff-0b973b67f859d3b8fa68baec97534643R98

    More instances of indexing in to a non-null-narrowed {} | undefined which is now an unknown instead.

  13. RyanCavanaugh commented on May 14, 2019

    @RyanCavanaugh
    Member

    microsoft/vscode@fd1ac75#diff-0f1abf8ff5283dac48ea3231f2dddfa0R96

    An interesting case. This is a typical unsound method declaration where the derived class needs a specialized object from a parallel class hierarchy and would be broken by a call through a base type alias. Method bivariance allows this, but until a subsequent change this was disallowed due to differing definitions of the return type of getTelemetryDescriptor

    The change appears to be unnecessary due to the change (presumably made chronologically later as Matt was fixing stuff) to getTelemetryDescriptor at microsoft/vscode@fd1ac75#diff-d6d4527bd487a54f95c554d21f5e05eb

    Update: Also microsoft/vscode@fd1ac75#diff-022291e875d46b01fc7f4e6ba724f466

  14. RyanCavanaugh commented on May 14, 2019

    @RyanCavanaugh
    Member
  15. ahejlsberg commented on May 14, 2019

    @ahejlsberg
    Member

    Matt Bierner (@mjbvz) Regarding this one

    [15:39:42] Error: /Users/matb/projects/vscode/src/vs/workbench/services/themes/common/fileIconThemeData.ts(121,7): Type 'any' is not assignable to type 'never'.
    

    This is an effect of #30769. The type FileIconThemeData["id" | "label" | "description" | "settingsId" | "extensionData" | "styleSheetContent" | "hasFileIcons" | "hidesExplorerArrows" | "hasFolderIcons" | "watch"] reduces to never when it is the target of an assignment because the properties are of disjoint types, i.e. there exists no type for which it is safe to perform this assignment.

  16. RyanCavanaugh commented on May 14, 2019

    @RyanCavanaugh
    Member

    microsoft/vscode@fd1ac75#diff-00578f406c825a8136fefeb491625f65L722

    In 3.4, promise has type Promise<{} | null>, which is allowed to be used for a Promise<ITaskSummary | null> because ITaskSummary only has optional properties. The type of this variable comes from three places in the function body that follows - Promise.resolve(null) (Promise<null>), a call to new Promise((c, e) => ... that produces Promise<{}>, and an ultimately-irrelevant call to this.taskService.run(task) that returns Promise<ITaskSummary>. It's unsafe because we can't really say what's going in to c( at line 736 (and indeed, this seems to be an incorrect value undefined).

    In 3.5, the Promise<{}> becomes Promise<unknown> and the whole thing becomes Promise<unknown>, and unknown can't be ITaskSummary | null

    The better fix is probably to annotate the untyped Promise constructor call. I'm still confused why TS is allowing an undefined to to through this codepath.

  17. RyanCavanaugh commented on May 14, 2019

    @RyanCavanaugh
    Member

    microsoft/vscode@fd1ac75#diff-4a12537872685c49f4dc5c42f1537c45

    I don't understand what this change is doing. The only manifestation of the type parameter in ITreeContextMenuEvent<RenderableMatch | null> is element: T | null;, so including | null here should not have changed anything. There's no error locally when I revert this

  18. RyanCavanaugh commented on May 14, 2019

    @RyanCavanaugh
    Member

    microsoft/vscode@fd1ac75#diff-203c27e756d1503a7f55c19fd8440959R268

    A simplified version:

    enum E { f, g }
    type A = {
      q?: E;
      x?: string;
      y?: string;
    }
    
    function set(a: A, key: keyof A, value: string) {
      a[key] = value;
    }

    This is a correct error; it happens that no one called set(a, "q", "foo"), but the code doesn't appear to guard against this at all.

    A preferable fix would be to change the signature of set / fillProperty to reject keys that didn't have corresponding string property types

  19. mjbvz commented on May 15, 2019

    @mjbvz
    Author

    Thank you for taking a look. For #31380 (comment), is that TS error or a VS Code error?

    I believe the only one that I think is really blocking us then is the d.ts change: #27089

  20. RyanCavanaugh commented on May 15, 2019

    @RyanCavanaugh
    Member

    is that TS error or a VS Code error?

    It's a VS Code error IMO. The object has a field that is either surplus in one constituent of the union, or an incorrect type in the other constituent.

  21. mjbvz commented on May 24, 2019

    @mjbvz
    Author

    Closing this as I believe the errors have all be addressed or are by-design

  22. NoelAbrahams commented on Jun 5, 2019

    @NoelAbrahams

    Matt Bierner (@mjbvz)

    Inferring T as unknown results in the error

    Build:Property 'hasOwnProperty' does not exist on type 'T

    in the following:

    public foo<T>(target: T): void {
    
                target.hasOwnProperty;
    }

    Not sure if you are seeing this as a bug. It is certainly rather inconvenient because hasOwnProperty does exist.

  23. weswigham commented on Jun 5, 2019

    @weswigham
    Member

    Pass undefined for T and be amazed at how hasOwnProperty does not exist. ❤️

    That's exactly the class of error the constraint change is supposed to catch - you might want to say T extends object 😉

  24. NoelAbrahams commented on Jun 5, 2019

    @NoelAbrahams

    Wesley Wigham (@weswigham) good point. Althought the temptation is to write (target as {}).hasOwnProperty as the relation to undefined is not very clear - unless you're a smart arse 😉

    Thanks

  25. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions