supabase / auth-js

An isomorphic Javascript library for Supabase Auth.
MIT License
355 stars 160 forks source link

Using verbatimModuleSyntax in tsconfig.json causes type check failure #833

Closed asciiwhite closed 3 months ago

asciiwhite commented 9 months ago

Bug report

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

dbm03 commented 8 months ago

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.

J0 commented 3 months ago

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!