Skip to content
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

fix(core): make AmplifyOutputs category types as unknown #14153

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

ashwinkumar6
Copy link
Member

@ashwinkumar6 ashwinkumar6 commented Jan 22, 2025

Description of changes

Solves issues where Typescript inferred type from amplify_outputs.json file is strongly typed when compared to AmplifyOutputs type. Updates AmplifyOutputs type to make all category key's as unknown.

Other changes:

  • Rename current AmplifyOutputs type to AmplifyOutputsLegacy and add a deprecating warning.
    • AmplifyOutputs type publicly exposed from "aws-amplify/adapter-core" will expose AmplifyOutputsLegacy under the same name instead to avoid any breaking change.
  • Also, deprecate importing LegacyConfig and AmplifyOutputs types from "aws-amplify/adapter-core"

Issue #, if available

A long term solution for issues like #14045, #14106

Description of how you validated changes

  • Linked and tested in sampleApp locally
  • E2E CI run (in progress)

Checklist

  • PR description included
  • yarn test passes
  • Unit Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

Checklist for repo maintainers

  • Verify E2E tests for existing workflows are working as expected or add E2E tests for newly added workflows
  • New source file paths included in this PR have been added to CODEOWNERS, if appropriate

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

mappedBuckets[name] = {
bucketName,
region,
paths: sanitizedPaths,
paths,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -296,27 +296,39 @@ export function parseAmplifyOutputs(
const resourcesConfig: ResourcesConfig = {};

if (amplifyOutputs.storage) {
resourcesConfig.Storage = parseStorage(amplifyOutputs.storage);
resourcesConfig.Storage = parseStorage(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think type casting is the best way here. IMO we should add guard rails in the parse* functions to make sure types hold and throw errors earlier if something is messed up

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, a type predicate should allow us to drop tha casting?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed async, decided to go ahead with type casting in this PR with a follow-up item to add run-time checks during parsing

@ashwinkumar6 ashwinkumar6 force-pushed the amplifyOutputs-deepPartial branch from 0d1cbae to 5da2834 Compare January 25, 2025 02:06
@@ -8,7 +8,9 @@ export {
createUserPoolsTokenProvider,
} from './authProvidersFactories/cognito';
export {
/** @deprecated This type is deprecated and will be removed in future versions. */
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be publicly exposed, updated for internal use via 'aws-amplify/adapter-core/internals'

@@ -40,10 +40,10 @@ import {
} from './singleton/types';

export function isAmplifyOutputs(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sanity check: have we verified this change wouldnt affect if someone extracted type by using Parameters<typeof ...>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amplify.configure no longer users AmplifyOutputs type, instead it uses AmplifyOutputsUnknown. That means
customers will not be able to extract inner nested AmplifyOutputs category properties

import { AmplifyOutputs } from "aws-amplify/adapter-core";

type AmplifyOutputsAuth = Extract<
  Parameters<typeof Amplify.configure>[0],
  AmplifyOutputs
>["auth"];

type AuthOauth = NonNullable<AmplifyOutputsAuth>["oauth"];

In the example above post our change AuthOauth would be never

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However customers can continue using the now deprecated AmplifyOutputs types from "aws-amplify/adapter-core"

Screenshot 2025-01-29 at 5 12 44 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants