-
Notifications
You must be signed in to change notification settings - Fork 707
Fix: Remove definite assignment assertions from class property declaration files #1751
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: Remove definite assignment assertions from class property declaration files #1751
Conversation
Co-authored-by: jakebailey <[email protected]>
Co-authored-by: jakebailey <[email protected]>
Co-authored-by: jakebailey <[email protected]>
Co-authored-by: jakebailey <[email protected]>
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.
Pull Request Overview
This PR fixes a bug where definite assignment assertions (!
) were being preserved in declaration files when they should be removed. The TypeScript compiler removes these assertions from .d.ts
files since they are only relevant during compilation and not in the final type declarations.
- Added test cases to verify the fix for definite assignment assertions in declaration files
- Implemented logic to remove exclamation tokens from property declarations in declaration files
- Updated existing baselines to reflect the corrected behavior
Reviewed Changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated no comments.
File | Description |
---|---|
testdata/tests/cases/compiler/definiteAssignmentAssertionInDeclaration.ts |
Basic test case for definite assignment assertion removal |
testdata/tests/cases/compiler/definiteAssignmentAssertionInDeclarationExtended.ts |
Extended test case covering various property types and modifiers |
internal/transformers/declarations/transform.go |
Implementation of the fix to remove exclamation tokens from declaration files |
Multiple baseline files | Updated reference outputs showing corrected behavior with exclamation tokens removed |
@copilot Remove the newly added tests and baselines, leaving only the changes to the existing test baselines. The existing tests turned out to cover everything. |
…lity Co-authored-by: jakebailey <[email protected]>
Removed the newly added test files and their baselines. The existing tests in |
… exclamation tokens Co-authored-by: jakebailey <[email protected]>
Fixes an issue where definite assignment assertions (
!
) were incorrectly preserved in TypeScript declaration files for class properties, causing compilation errors.Problem
When generating declaration files (
.d.ts
), the TypeScript compiler should remove definite assignment assertions since they are not valid in ambient contexts. However, tsgo was preserving these assertions on class properties, leading to:Solution
Modified the declaration transformer to detect and remove exclamation tokens (
KindExclamationToken
) from class property declarations when generating declaration files. The fix only applies to property declarations in classes, as property signatures in interfaces cannot have definite assignment assertions.Files changed:
internal/transformers/declarations/transform.go
: UpdatedtransformPropertyDeclaration
to filter out definite assignment assertionsResult
The fix now correctly generates declaration files without definite assignment assertions on class properties:
This change aligns tsgo's behavior with the official TypeScript compiler and eliminates the compilation errors that were occurring in declaration files.
Testing
definiteAssignmentAssertions.ts
and other submodule tests!
tokens from class propertiesFixes #1736
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.