TSConfig for osdk

Hi, I am using the integrating osdk client v2.0.9 to an already existing app that uses Express framework.

my tsconfig module is commonjs.

I can run in dev mode fine using npx tsx src/index.ts. However, I am getting problems building using tsc to generate the dist folder. Example errors are

node_modules/@osdk/api/build/esm/objectSet/ObjectSet.d.ts:44:5 - error TS1128: Declaration or statement expected.

44     readonly fetchPageWithErrors: <L extends PropertyKeys<Q>, R extends boolean, const A extends Augments, S extends NullabilityAdherence = NullabilityAdherence.Default>(args?: FetchPageArgs<Q, L, R, A, S>) => Promise<Result<PageResult<Osdk.Instance<Q, ExtractOptions<R, S>, L>>>>;
       ~~~~~~~~

node_modules/@osdk/api/build/esm/objectSet/ObjectSet.d.ts:44:61 - error TS1005: '?' expected.

44     readonly fetchPageWithErrors: <L extends PropertyKeys<Q>, R extends boolean, const A extends Augments, S extends NullabilityAdherence = NullabilityAdherence.Default>(args?: FetchPageArgs<Q, L, R, A, S>) => Promise<Result<PageResult<Osdk.Instance<Q, ExtractOptions<R, S>, L>>>>;

and

node_modules/type-fest/source/sum.d.ts:68:10 - error TS1005: ',' expected.

68          : never
            ~

node_modules/type-fest/source/sum.d.ts:69:7 - error TS1005: ',' expected.

69       : never) & number

My tsconfig is as follows:

{
  "compilerOptions": {
    "module": "commonjs",
    "esModuleInterop": true,
    "resolveJsonModule": true,
    "target": "es6",
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noImplicitAny": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "outDir": "dist",
    "baseUrl": ".",
    "paths": {
      "*": ["node_modules/*"]
    }
  },
  "include": ["src/**/*"]
}

How should the tsconfig look like (I’m quite new to typescript)? Also, do you have an example code for OSDK + Express? The application I am building is purely backend.

Hello there,

I think there are probably a few things at play for you right now.

  1. The 2.0 OSDK is pure ESM and as such using it from commonjs will require doing a dynamic import in versions of node prior to the latest v22. First example I found on stack overflow: https://stackoverflow.com/questions/70396400/how-to-use-es6-modules-in-commonjs
  2. Typefest requires a minimum of Typescript 5.1 and the V2 OSDK types are based on Typescript 5.4.

After a quick look at the tsx project, it looks like it isn’t compiling your typescript with the typechecker but simply using esbuild to produce javascript on the fly. So the conversion in esbuild is possible but when you try to compile with typechecking via tsc it is failing.

My guess is just getting to typescript 5.x (I think latest is 5.6?) would solve this for you but you may also have to add dynamic imports.

Thanks for the detailed explanation. Upgrading typescript helped with the typefest error :). Trying out number 1,…