-
Notifications
You must be signed in to change notification settings - Fork 579
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
Library fails in typescript compilation with exactOptionalPropertyTypes=true #6668
Comments
Hey @FranzZemen , Could you please provide a minimal code reproduction? The error occurs because with Thanks! |
I worked on this a fair bit- The dependencies I have "dependencies": {
"@aws-sdk/client-cloudwatch-logs": "^3.693.0",
"@aws-sdk/client-dynamodb": "^3.693.0",
"@aws-sdk/client-s3": "^3.693.0",
"@aws-sdk/credential-providers": "^3.693.0",
"@aws-sdk/lib-dynamodb": "^3.693.0",
"@types/node": "^20.2.0",
"ts-node": "^x.x.x",
"typescript": "^5.6.3"
} In tsconfig.json, I set I ran import {
DynamoDBClient,
BatchExecuteStatementCommand,
BatchStatementRequest,
AttributeValue
} from "@aws-sdk/client-dynamodb";
// Define interfaces
interface Item {
id: string;
name: string;
category?: string;
price?: number;
}
interface BatchOperationResponse {
success: boolean;
data?: any;
error?: Error;
}
// DynamoDB client configuration
const client = new DynamoDBClient({
region: "us-west-2"
});
// Main batch operation function
async function executeBatchStatements(items: Item[]): Promise<BatchOperationResponse> {
const statements: BatchStatementRequest[] = items.map((item) => {
const parameters: AttributeValue[] = [
{ S: item.id },
{ S: item.name },
item.category ? { S: item.category } : { NULL: true },
item.price !== undefined ? { N: item.price.toString() } : { NULL: true }
];
return {
Statement: "INSERT INTO Products VALUE {'id': ?, 'name': ?, 'category': ?, 'price': ?}",
Parameters: parameters,
ConsistentRead: true
};
});
try {
const command = new BatchExecuteStatementCommand({
Statements: statements
});
const response = await client.send(command);
if (response.Responses) {
const errors = response.Responses.filter(r => r.Error);
if (errors.length > 0) {
console.warn('Some statements failed:', errors);
}
}
return {
success: true,
data: response.Responses
};
} catch (error) {
console.error('Batch operation failed:', error);
return {
success: false,
error: error as Error
};
}
}
// Batch read operation
async function batchReadItems(ids: string[]): Promise<BatchOperationResponse> {
const statements: BatchStatementRequest[] = ids.map(id => ({
Statement: "SELECT * FROM Products WHERE id = ?",
Parameters: [{ S: id }],
ConsistentRead: true
}));
try {
const command = new BatchExecuteStatementCommand({
Statements: statements
});
const response = await client.send(command);
return {
success: true,
data: response.Responses
};
} catch (error) {
console.error('Batch read operation failed:', error);
return {
success: false,
error: error as Error
};
}
}
// Example usage
async function main() {
const items: Item[] = [
{
id: "1",
name: "Product 1",
category: "Electronics",
price: 299.99
},
{
id: "2",
name: "Product 2",
category: "Books",
price: 19.99
}
];
console.log('Executing batch insert...');
const insertResult = await executeBatchStatements(items);
console.log('Insert result:', insertResult);
console.log('Executing batch read...');
const readResult = await batchReadItems(["1", "2"]);
console.log('Read result:', readResult);
}
// Execute with error handling
main()
.then(() => console.log('All operations completed'))
.catch(error => console.error('Error in main execution:', error));
Since I don't have the minimal code reproduction yet, I'd like to suggest to check the types, and use precise types instead of If you still have questions, please share minimal code reproduction and we can help you from there! Thanks! |
In the repo below, in tsconfig.base.json, with Commands: git clone https://github.com/FranzZemen/aws.3.693.0.bug Or find relevant info below Repo @franzzemen/aws.3.693.0.bug If more convenient here are the need files. Test src below (can't attach .ts file) source file contents, place in ./src/test.ts import {DynamoDBDocument} from '@aws-sdk/lib-dynamodb';
import {DynamoDBClient} from '@aws-sdk/client-dynamodb';
export class DynamoClient {
private documentClient: DynamoDBDocument;
private dbClient: DynamoDBClient;
constructor() {
this.dbClient = new DynamoDBClient();
this.documentClient = DynamoDBDocument.from(this.dbClient, {
marshallOptions: {
removeUndefinedValues: true
}
});
}
} |
And even simpler repro with some additional context in the readme can be found at: https://github.com/monholm/aws-sdk-ts-repro The issue was introduced in |
merged #6683, will be released in the next published version expected tomorrow. |
Checkboxes for prior research
Describe the bug
Pretty simple. Set exactOptionalPropertyTypes=true in 3.693.0 (this morning's latest NPM release) and compile. You will get transpiration errors such as:
BatchStatementRequest' is not assignable to type '{ Parameters?: any[]; }' with 'exactOptionalPropertyTypes: true
Set it to false, and there is no issue.
This causes problems for any project that is using the flag.
I have the following installed in my npm dependencies:
It does NOT happen in 3.687.0. Not sure about versions in between.
Node V20.2.0, Typescript 5.6.3 for both working and non-working versions
Regression Issue
SDK version number
@aws-sdk/[email protected]
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
Node V20.2.0, Typescript 5.6.3
Reproduction Steps
set exactOptionalPropertyTypes=true and transpile using tsc
Observed Behavior
Typescript errors within AWS v3 library such as
BatchStatementRequest' is not assignable to type '{ Parameters?: any[]; }' with 'exactOptionalPropertyTypes: true
Expected Behavior
No typescript errors
Possible Solution
workaround is to set exactOptionalPropertyTypes=false
Additional Information/Context
No response
The text was updated successfully, but these errors were encountered: