Skip to content

TypeScript: can't find built-in utility types if "noLib": true #106

@johhnry

Description

@johhnry

Hi,

Thanks for making those type definitions, this is really helpful to be able to use TypeScript for Adobe products!

This is a sample config for tsconfig.json and package.json:

// tsconfig.json
{
  "compilerOptions": {
    "module": "none",
    "noLib": true,
    "types": ["types-for-adobe/Photoshop/2015.5"],
    "strict": true,
    "target": "ES3",
    "downlevelIteration": true
  },
  "include": ["src/**/*"]
}
// package.json
{
  // ...
  "dependencies": {
    "types-for-adobe": "^7.0.12",
    "typescript": "^4.9.5"
  }
}

I found that this minimal example compiles but raise a TypeScript error during compilation:

// error TS2318: Cannot find global type 'Extract'.
function fn<T>(object: T) {
  for (const key in object) {}
}

// Note that this works:
function fn(object: any) {
  for (const key in object) {}
}

I don't know the internals of how the for ... in gets compiled using generics but it made me realize that I can't use any of the utility types when using "noLib": true in tsconfig.json:

// error TS2304: Cannot find name 'Extract'.
type T0 = Extract<"a" | "b" | "c", "a" | "f">;

This is because utility types are located in lib.es5.d.ts therefore not included with noLib.

I can still copy the Extract type definition in my project but maybe we can include them in the repository?

// Compiles fine
type Extract<T, U> = T extends U ? T : never;

function fn<T>(object: T) {
  for (const key in object) {}
}

Thanks!

Metadata

Metadata

Assignees

No one assigned

    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