1

Promise.try recently became available in Baseline 2025.

I wanted to know how can I enable this in a TypeScript project.

I'm currently using TypeScript 5.7.3 and have the following tsconfig.json:

{
  "extends": "../../tsconfig.base.json",
  "compilerOptions": {
    "module": "ESNext",
    "noImplicitOverride": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "noPropertyAccessFromIndexSignature": true,
    "jsx": "react-jsx"
  },
  "files": [],
  "include": ["src/types/**/*.ts", "src/**/*.ts", "src/**/*.tsx"],
  "references": [
    {
      "path": "./tsconfig.lib.json"
    }
  ]
}

tsconfig.base.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "rootDir": ".",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "esModuleInterop": true,
    "target": "ES2024",
    "module": "ESNext",
    "lib": ["ES2024", "DOM", "ESNext", "ES2024.Promise"],
    "skipLibCheck": true,
    "skipDefaultLibCheck": true,
    "allowSyntheticDefaultImports": true,
    "baseUrl": ".",
    "strict": true,
    "strictNullChecks": true,
    "forceConsistentCasingInFileNames": true,
    "types": ["node"],
    "paths": {
      "@alertdown/auth": ["libs/auth/src/index.ts"],
      "@alertdown/common": ["libs/common/src/index.ts"],
      "@alertdown/core": ["libs/core/src/index.ts"],
      "@alertdown/db": ["libs/db/src/index.ts"],
      "@alertdown/email": ["libs/email/src/index.ts"],
      "@alertdown/google": ["libs/google/src/index.ts"],
      "@alertdown/infrastructure": ["libs/infrastructure/src/index.ts"],
      "@alertdown/llm": ["libs/llm/src/index.ts"],
      "@alertdown/notifications": ["libs/notifications/src/index.ts"],
      "@alertdown/payments": ["libs/payments/src/index.ts"],
      "@alertdown/playwright": ["libs/playwright/src/index.ts"],
      "@alertdown/prototyping": ["libs/prototyping/src/index.ts"],
      "@alertdown/site": ["libs/site/src/index.ts"],
      "@alertdown/site-domain": ["libs/site-domain/src/index.ts"],
      "@alertdown/storage": ["libs/storage/src/index.ts"],
      "@alertdown/stripe": ["libs/stripe/src/index.ts"],
      "@alertdown/temporal-client": ["libs/temporal-client/src/index.ts"],
      "@alertdown/ui": ["libs/ui/src/index.ts"]
    }
  },
  "exclude": ["node_modules", "tmp"]
}

I thought ESNext would cover all the cases or ES2024 would do.

I get: Property 'try' does not exist on type 'PromiseConstructor'.ts(2339)

I could potentially augment Promise, but I'd like to avoid it as it's part of the spec.

Any ideas?

1 Answer 1

4

Promise.try() was added to the ESNext TypeScript library in microsoft/TypeScript#60232 which was merged into the main branch on November 5, 2024, after TypeScript 5.7 was released. So it's not available in any current production release yet. If you want to use it today you can upgrade to TypeScript 5.8 Beta as shown in the Playground link below. Or you can wait until TypeScript 5.8 is released on February 25, 2025 according to microsoft/TypeScript#61023.

Playground link to code in TS5.8 Beta

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks jcalz. TypeScript 5.8 was released. How can I enable it in the libs? I've tried setting "ESNext.Promise" but the LSP won't show it up
Wait, got it. I was using vscode: I had to (Ctrl + P / Command + P) Then > Select TypeSript Version and told it to use the workspace one. Nice!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.