Better typings
Is this related to a new or existing framework?
No response
Is this related to a new or existing API?
Authentication
Is this related to another service?
No response
Describe the feature you'd like to request
The typings aren't correct, they only have to methods and they often returns any. Maybe we are missing something but in a Typescript environment this is very painful to deal with.
Describe the solution you'd like
Includes all the property in the class declaration.
export class CognitoUserPool {
constructor(
data: ICognitoUserPoolData,
wrapRefreshSessionCallback?: (
target: NodeCallback.Any
) => NodeCallback.Any
);
...
public advancedSecurityDataCollectionFlag: boolean
public clientId: string
public userPoolId: string
...
}
Describe alternatives you've considered
Declaring our own typings for @aws-amplify/auth
Additional context
No response
Is this something that you'd be interested in working on?
- [X] 👋 I may be able to implement this feature request
- [ ] ⚠️ This feature might incur a breaking change
I just wrote some types if you want to use them :
declare module 'amazon-cognito-identity-js' {
enum AuthenticationFlowType {
USER_SRP_AUTH = 'USER_SRP_AUTH',
USER_PASSWORD_AUTH = 'USER_PASSWORD_AUTH',
CUSTOM_AUTH = 'CUSTOM_AUTH',
}
interface CognitoUser {
attributes: {
email: string
email_verified: true
family_name: string
given_name: string
phone_number: string
phone_number_verified: boolean
sub: string
}
pool: CognitoUserPool
authenticationFlowType: AuthenticationFlowType
keyPrefix: string
signInUserSession: CognitoUserSession
userDataKey: 'CognitoIdentityServiceProvider'
username: string
}
interface CognitoUserPool {
advancedSecurityDataCollectionFlag: boolean
clientId: string
userPoolId: string
}
interface CognitoUserSession {
clockDrift: number
idToken: CognitoIdToken
accessToken: CognitoAccessToken
refreshToken: CognitoRefreshToken
}
interface CognitoIdToken {
jwtToken: string
payload: {
sub: string
email_verified: boolean
iss: string
phone_number_verified: boolean
'cognito:username': string
given_name: string
origin_jti: string
aud: string
event_id: string
token_use: string
auth_time: number
phone_number: string
exp: number
iat: number
family_name: 'Monier'
jti: string
email: string
}
}
interface CognitoAccessToken {
jwtToken: string
payload: {
origin_jti: string
sub: string
event_id: string
token_use: string
scope: string
auth_time: number
iss: string
exp: number
iat: number
jti: string
client_id: string
username: string
}
}
interface CognitoRefreshToken {
token: string
}
}
Can we please get better Typescript typings 🙏
@jordanmonier hey Jordan, according to your code, I apply it to my code and got this error in the payload Property:
(property) CognitoIdToken.payload: {
[key: string]: any;
}
Subsequent property declarations must have the same type. Property 'payload' must be of type '{ [key: string]: any; }', but here has type '{ sub: string; email_verified: boolean; iss: string; phone_number_verified: boolean; 'cognito:username': string; given_name: string; origin_jti: string; aud: string; event_id: string; token_use: string; ... 6 more ...; email: string; }'.ts(2717)
index.d.ts(356, 3): 'payload' was also declared here.
Can anyone have a better typescript typings please tell us know!
+1
+1
These types are all defined, and in many cases as Classes not just interfaces. They're just in transitive dependencies that are annoyingly flagged as "internal" and for some reason aren't always available for imports. I think aws-amplify really needs to be re-exporting these types if developers are expected to not directly install the transitive dependencies.
For example I'm able to use the following:
import { CognitoUser } from '@aws-amplify/auth'
import { CognitoUserSession, CognitoIdToken } from 'amazon-cognito-identity-js'
So long as I have @aws-amplify/auth in my dependencies:
"aws-amplify": "5.3.16",
"@aws-amplify/auth": "5.6.10",
I'm not sure why I have to explicitly depend on @aws-amplify/auth but I do.