Search code examples
typescriptvisual-studio-codeautocompleteintellisense

Visual Studio Code (VS-code) Typescript Intellisense no suggestions in Omit


so I noticed that the IntelliSense for Typescript in Visual Studio Code is not working properly in specific cases.

One of the problems where the IntelliSense is not working correctly is when using the Omit utility of Typescript. This type lets you create new types / interfaces where you exclude certain properties of an existing type / interface. Now my issue is that the i get no IntelliSense whatsoever when I try to Omit a given interface. For instance:

interface Article {
  name: string
  price: number
  stock: number
}

interface TestArticle extends Omit<Article, '<Article-interface-property>'> {}

In this example I get to no suggestions for the properties of the Article interface. However, when use the IntelliSense of IntelliJ i all the Article's properties are suggested. Therefore, I am wondering what I am missing to improve the IntelliSense for Typescript in Visual Studio Code.

I am using the following extensions:

  • npm Intellisense
  • EsLint
  • JavaScript and TypeScript Nightly

I am using the following typescript version: "typescript": "^5.4.5" and "ts-node": "^10.9.1"

I have also tried to change the version used for Typescript in Visual Studio Code from Vs-codes's version to the version installed in the workspace. However, this has also resolved the issue at hand. Typescript Version used in Vs-Code

I have also set "typescript.validate.enable": true, as proposed here. Unfortunately this did not solve the problem either.


Solution

  • The second type parameter of the built-in Omit utiltiy is not typed (typed as any).

    type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
    

    You can make your own typed:

    type OmitTyped<Obj extends object, Keys extends keyof Obj> = Pick<
      Obj,
      Exclude<keyof Obj, Keys>
    >;
    
    // or simpler
    type OmitTyped<Obj extends object, Keys extends keyof Obj> = Omit<Obj, Keys>
    

    enter image description here