spotify / spotify-web-api-ts-sdk

A Typescript SDK for the Spotify Web API with types for returned data.
Other
356 stars 69 forks source link

[BUG] MaxInt instantiation is excessively deep and possibly infinite (TypeScript < 4.5) #88

Open Michael-Ziluck opened 11 months ago

Michael-Ziluck commented 11 months ago

Error

When using TypeScript and the SDK, calling any function that uses MaxInt results in the following error:

TS2589: Type instantiation is excessively deep and possibly infinite.

When instantiating it in-line, the same thing also occurs:

const maxInt: MaxInt<50> = 50;

Even when trying it with the old version of MaxInt before https://github.com/spotify/spotify-web-api-ts-sdk/pull/48 has the same problem. Not sure how others have not reported it yet.

Versions

Output from npm --versions:

{                            
  'project-name': '0.0.0',
  npm: '8.15.0',             
  node: '16.17.0',           
  v8: '9.4.146.26-node.22',  
  uv: '1.43.0',              
  zlib: '1.2.11',            
  brotli: '1.0.9',           
  ares: '1.18.1',            
  modules: '93',             
  nghttp2: '1.47.0',         
  napi: '8',                 
  llhttp: '6.0.7',           
  openssl: '1.1.1q+quic',    
  cldr: '41.0',              
  icu: '71.1',               
  tz: '2022a',               
  unicode: '14.0',           
  ngtcp2: '0.1.0-DEV',       
  nghttp3: '0.1.0-DEV'       
}     

Output from npm list:

project-name@0.0.0 C:\Users\Michael\workspace\ProjectName
├── @angular-devkit/build-angular@12.2.18
├── @angular/animations@12.2.17
├── @angular/cli@12.2.18
├── @angular/common@12.2.17
├── @angular/compiler-cli@12.2.17
├── @angular/compiler@12.2.17
├── @angular/core@12.2.17
├── @angular/forms@12.2.17
├── @angular/platform-browser-dynamic@12.2.17
├── @angular/platform-browser@12.2.17
├── @angular/router@12.2.17
├── @spotify/web-api-ts-sdk@1.1.2
├── @types/jasmine@3.8.2
├── @types/node@12.20.55
├── jasmine-core@3.8.0
├── karma-chrome-launcher@3.1.1
├── karma-coverage@2.0.3
├── karma-jasmine-html-reporter@1.7.0
├── karma-jasmine@4.0.2
├── karma@6.3.20
├── rxjs@6.6.7
├── tslib@2.6.2
├── typescript@4.3.5
└── zone.js@0.11.8
Michael-Ziluck commented 11 months ago

It would appear it's because of TypeScript's depth limit. MaxInt<45> works fine, but MaxInt<46> and beyond all fail.

Also worth noting that MaxInt isn't even working as intended at the moment. This resolves and compiles fine when it should fail:

const pageSize: MaxInt<45> = 50;
Michael-Ziluck commented 11 months ago

Discovered the source of the problem. This SDK does not constrain the TypeScript version but is unusable by any version of TypeScript before 4.5 as that is when they added tail-recursion elimination.

For now I'll just update but it is definitely worth looking into updating the package.json in this project to properly constrain packages.