auth-js icon indicating copy to clipboard operation
auth-js copied to clipboard

Using verbatimModuleSyntax in tsconfig.json causes type check failure

Open asciiwhite opened this issue 2 years ago • 1 comments

Bug report

  • [x] I confirm this is a bug with Supabase, not with my own application.
  • [x] I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

Using a tsconfig.json with enabled verbatimModuleSyntax causes type check issues.

vue-tsc --noEmit --composite false

node_modules/@supabase/gotrue-js/src/lib/errors.ts:1:10 - error TS1484: 'WeakPasswordReasons' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.

1 import { WeakPasswordReasons } from './types'
           ~~~~~~~~~~~~~~~~~~~

node_modules/@supabase/gotrue-js/src/lib/fetch.ts:3:3 - error TS1484: 'AuthResponse' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.

3   AuthResponse,
    ~~~~~~~~~~~~

node_modules/@supabase/gotrue-js/src/lib/fetch.ts:4:3 - error TS1484: 'AuthResponsePassword' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.

4   AuthResponsePassword,
    ~~~~~~~~~~~~~~~~~~~~

node_modules/@supabase/gotrue-js/src/lib/fetch.ts:5:3 - error TS1484: 'SSOResponse' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.

5   SSOResponse,
    ~~~~~~~~~~~

node_modules/@supabase/gotrue-js/src/lib/fetch.ts:6:3 - error TS1484: 'GenerateLinkProperties' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.

6   GenerateLinkProperties,
    ~~~~~~~~~~~~~~~~~~~~~~

node_modules/@supabase/gotrue-js/src/lib/fetch.ts:7:3 - error TS1484: 'GenerateLinkResponse' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.

7   GenerateLinkResponse,
    ~~~~~~~~~~~~~~~~~~~~

node_modules/@supabase/gotrue-js/src/lib/fetch.ts:8:3 - error TS1484: 'User' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.

8   User,
    ~~~~

node_modules/@supabase/gotrue-js/src/lib/fetch.ts:9:3 - error TS1484: 'UserResponse' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.

9   UserResponse,
    ~~~~~~~~~~~~

node_modules/@supabase/gotrue-js/src/lib/helpers.ts:1:10 - error TS1484: 'SupportedStorage' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.

1 import { SupportedStorage } from './types'
           ~~~~~~~~~~~~~~~~

node_modules/@supabase/gotrue-js/src/lib/types.ts:2:10 - error TS1484: 'Fetch' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.

2 import { Fetch } from './fetch'

Found 10 errors in 4 files.

Errors  Files
     1  node_modules/@supabase/gotrue-js/src/lib/errors.ts:1
     7  node_modules/@supabase/gotrue-js/src/lib/fetch.ts:3
     1  node_modules/@supabase/gotrue-js/src/lib/helpers.ts:1
     1  node_modules/@supabase/gotrue-js/src/lib/types.ts:2

To Reproduce

Add "verbatimModuleSyntax": true to "compilerOptions" inside your tsconfig.json.

Expected behavior

No type check issues should happen.

System information

  • Version of supabase-js: 2.39.2

asciiwhite avatar Jan 02 '24 15:01 asciiwhite

I had also a Type error in my application, even without setting "verbatimModuleSyntax" to true. The error in my case was in the method resolveFetch() of helpers.ts.

A valid fix for me was updating both Supabase and Typescript to the latest version.

dbm03 avatar Jan 25 '24 03:01 dbm03

You're right that using TypeScript 5 with verbatimModuleSyntax enabled will lead to errors. It sounds like it simplifies default typescript elision. This might be useful but I don't think we'll be supporting this just yet though. If you have time do you mind sharing when the flag would be critical?

If you remove the verbatimModuleSyntax on v2.64.2 there shouldn't be any errors. Going to close the issue for now but feel free to re-open if this is critical for your use and we will revisit.

Thanks!

J0 avatar Jun 17 '24 11:06 J0