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

Overlapping definition of string literals #4155

Closed
soulman-is-good opened this issue Jul 14, 2022 · 3 comments
Closed

Overlapping definition of string literals #4155

soulman-is-good opened this issue Jul 14, 2022 · 3 comments
Assignees
Labels
bug This issue is a bug. closed-for-staleness response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days.

Comments

@soulman-is-good
Copy link

soulman-is-good commented Jul 14, 2022

Describe the bug

Generating typescript from enum shape creates overlapping string literal definitions which renders them useless. No type autocomplete, no type checking works.

if (Array.isArray(shape.enum)) {
stringType = shape.enum.map(function(s) {
return '"' + s + '"';
}).join('|') + '|' + stringType;

Expected Behavior

Script generates proper string literals from enum shape:

@enum([
    {name: "Pending", value: "Pending"},
    {name: "Failed", value: "Failed"},
    {name: "Success", value: "Success"},
])
string Status

should generate

export type Status = "Pending"|"Failed"|"Success";

Current Behavior

Following structure in smithy:

@enum([
    {name: "Pending", value: "Pending"},
    {name: "Failed", value: "Failed"},
    {name: "Success", value: "Success"},
])
string Status

currently generates following definition file:

export type Status = "Pending"|"Failed"|"Success"|string;

Reproduction Steps

  1. have aws-sdk lib installed in the project
  2. run node v8 or grater in interactive mode from within the project dir. (just node)
  3. paste the following code:
const TSGenerator = require("aws-sdk/scripts/lib/ts-generator");

console.log(new TSGenerator({}).generateTypingsFromShape({}, "Status", {
    "type": "string",
    "enum": [
        "Pending",
        "Failed",
        "Success"
    ]
}));

See the output:

export type Status  = "Pending"|"Failed"|"Success"|string;

Possible Solution

Remove |string; postfix if this is enum, though this is a breaking change and I'm not sure if v3 healed that.

Additional Information/Context

No response

SDK version used

2.1174.0

Environment details (OS name and version, etc.)

MacOS 11.6.6, Amazon Linux 2

@soulman-is-good soulman-is-good added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 14, 2022
@ajredniwja
Copy link
Member

Hey thanks for opening this issue, I'll discuss with the team if any possible solutions, I havent tried but it should not be an issue with V3 of the SDK.

@ajredniwja ajredniwja self-assigned this Aug 1, 2022
@ajredniwja ajredniwja added response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Aug 1, 2022
@github-actions
Copy link

github-actions bot commented Aug 7, 2022

This issue has not received a response in 1 week. If you still think there is a problem, please leave a comment to avoid the issue from automatically closing.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Aug 7, 2022
@paul-vd
Copy link

paul-vd commented Aug 25, 2023

Fixed by #4482

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. closed-for-staleness response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days.
Projects
None yet
Development

No branches or pull requests

3 participants