Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find name 'Omit' in Typescript

Tags:

typescript

Background

I'm making my custom index.d.ts file on src/@types/index.d.ts. I needed to merge my type like below.

// src/@types/index.d.ts
declare namespace Admin {
  interface InitialStateFromDB {
    teamSettings: {
      teamPasswords: TeamPassword[],
      teamCount: number
    },
    adminPasswords: string,
    postInfos: PostInfo[] | undefined
  }
  interface InitialState extends Omit<InitialStateFromDB, 'adminPasswords'> {
    adminPasswords: AdminPassword
  }
}

Problem

I got error : Cannot find name 'Omit'.ts(2304) by VSCode Intellisense. But compile worked well.

So, I made Omit type type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>> (copied in here)

And after compile, I got another error : 'Omit' was also declared here.

What should I do in this case? Just ignore IntelliSense's error ?

like image 312
Byeongin Yoon Avatar asked Jun 04 '19 08:06

Byeongin Yoon


4 Answers

Omit was only recently added in TS 3.5.1 so you may be using an older version of TS in your workspace that does not support it yet.

Make sure your VS Code workspace is using the same version of TypeScript you are compiling with by following these instructions. Just open a TS file run the Select TypeScript Version command in VS Code, and opt to use your workspace version of TypeScript (which should be 3.5.1)

like image 95
Matt Bierner Avatar answered Sep 29 '22 21:09

Matt Bierner


try using "skipLibCheck": true as one of compilerOptions in your tsconfig.json file

like image 20
adnan2nd Avatar answered Sep 29 '22 22:09

adnan2nd


Press ctrl + shift + p in vscode and type TypeScript and select "TypeScript: Select TypeScript Version"

like image 45
jefferson luiz Avatar answered Sep 29 '22 21:09

jefferson luiz


Use typescript version 3.5.x

And if you are using Angular version 6, then upgrade it to 8.2.2

You can check following package versions in package.json

"dependencies": {
    "@angular-devkit/build-angular": "^0.803.24",
    "@angular/animations": "^8.2.2",
    "@angular/cdk": "^8.2.2",
    "@angular/common": "^8.2.2",
    "@angular/compiler": "^8.2.2",
    "@angular/core": "^8.2.2",
    "@angular/forms": "^8.0.0",
    "@angular/http": "^8.0.0-beta.10",
    "@angular/material": "^8.2.2",
    "@angular/platform-browser": "^8.2.2",
    "@angular/platform-browser-dynamic": "^8.2.2",
    "@angular/router": "^6.0.0",
    "@material/dialog": "^4.0.0",
    "@ng-bootstrap/ng-bootstrap": "^4.0.0",
    "@ngx-translate/core": "^10.0.1",
    "@ngx-translate/http-loader": "^3.0.1",
    "@syncfusion/ej2-angular-charts": "^17.4.51",
    "@syncfusion/ej2-angular-diagrams": "^17.4.51",
    "@syncfusion/ej2-angular-grids": "^17.4.51",
    "@syncfusion/ej2-diagrams": "^17.4.51",
    "chart.js": "^2.7.2",
    "core-js": "^2.5.5",
    "file-saver": "^2.0.1",
    "font-awesome": "^4.7.0",
    "html2canvas": "^1.0.0-alpha.3",
    "jspdf": "^1.5.3",
    "lodash": "^4.17.15",
    "ng2-charts": "^1.6.0",
    "nyc": "^15.1.0",
    "rxjs": "^6.4.0",
    "stream": "0.0.2",
    "timers": "^0.1.1",
    "xml2js": "^0.4.19",
    "yarn": "^1.6.0",
    "zone.js": "^0.9.1"
},
"devDependencies": {
    "@angular/cli": "^8.2.2",
    "@angular/compiler-cli": "^8.2.2",
    "@angular/language-service": "^8.2.2",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/lodash": "4.14.116",
    "@types/node": "^9.6.1",
    "@types/xml2js": "^0.4.3",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~3.1.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^4.4.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.4.2",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^1.0.0",
    "protractor": "^6.0.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1",
    "typescript": "^3.5.3"
}
like image 45
Shrishailya Sutar Avatar answered Sep 29 '22 21:09

Shrishailya Sutar