-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update types to allow either app or user auth #113
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,11 +117,16 @@ export default class Twitter { | |
Currently Twitter themselves convert it to strings for the API though, so this change will come some time in the far future. */ | ||
type snowflake = string; | ||
|
||
interface TwitterOptions { | ||
type TwitterOptions = TwitterOptionsUserAuthentication | TwitterOptionsAppAuthentication | ||
|
||
interface TwitterOptionsBasics { | ||
/** "api" is the default (change for other subdomains) */ | ||
subdomain?: string; | ||
/** version "1.1" is the default (change for other subdomains) */ | ||
version?: string; | ||
} | ||
|
||
interface TwitterOptionsUserAuthentication extends TwitterOptionsBasics { | ||
/** consumer key from Twitter. */ | ||
consumer_key: string; | ||
/** consumer secret from Twitter */ | ||
|
@@ -131,7 +136,20 @@ interface TwitterOptions { | |
/** access token secret from your User (oauth_token_secret) */ | ||
access_token_secret?: OauthTokenSecret; | ||
/** bearer token */ | ||
bearer_token?: string; | ||
bearer_token?: never; | ||
} | ||
|
||
interface TwitterOptionsAppAuthentication extends TwitterOptionsBasics { | ||
/** consumer key from Twitter. */ | ||
consumer_key?: never; | ||
/** consumer secret from Twitter */ | ||
consumer_secret?: never; | ||
/** access token key from your User (oauth_token) */ | ||
access_token_key?: never; | ||
/** access token secret from your User (oauth_token_secret) */ | ||
access_token_secret?: never; | ||
Comment on lines
+144
to
+150
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. defining all the keys as "never" seems a bit useless to me. If we were to define the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank's @T0TProduction for your feedback. The problem is that unions in TypeScript are not exclusive (see microsoft/TypeScript#14094). This StackOverflow comment sums the problem up: https://stackoverflow.com/a/61281828 I tried to use types instead of interfaces as you described it, but the problem remained the same. In my opinion, we should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see! I just checked the code, and now I'm a bit confused though: |
||
/** bearer token */ | ||
bearer_token: string; | ||
} | ||
|
||
type OauthToken = string; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as mentioned in the other comment, is never really needed?