Repository navigation
🐛 Only use the fallback provider if Reflect has the whole metadata API - #175
Open
Alec Gibson (alecgibson) wants to merge 1 commit into
Open
Alec Gibson (alecgibson) wants to merge 1 commit into
Alec Gibson (alecgibson) wants to merge 1 commit into
Conversation
Fixes microsoft#165 When `Reflect.defineMetadata` exists but the registry doesn't, `CreateMetadataRegistry` wraps the existing `Reflect` in a fallback provider. The provider captures five methods, and `isProviderFor` calls `getOwnMetadataKeys` on every lookup. So if some other library put only part of the API on `Reflect`, every metadata lookup throws `TypeError: getOwnMetadataKeys is not a function`. To reproduce: 1. Install `reflect-metadata@0.2.2` and `@abraham/reflection`, which defines `defineMetadata` but not `getOwnMetadataKeys`. 2. Import `@abraham/reflection` before `reflect-metadata`. 3. Call `Reflect.getOwnMetadata("a", {})`. It throws the error above. With this change, the fallback is only used when all five methods it captures are functions. Otherwise `reflect-metadata` installs its own implementation, as it does when no metadata API is present. The trade-off is that metadata written through an incomplete implementation before `reflect-metadata` loads can't be read afterwards, which is better than failing on every lookup. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Author
|
@microsoft-github-policy-service agree company="Reedsy" |
Alec Gibson (alecgibson)
marked this pull request as ready for review
September 24, 2026 10:06
|
Alec Gibson (@alecgibson) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
Author
|
@microsoft-github-policy-service agree company="Reedsy" |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #165
When
Reflect.defineMetadataexists but the registry doesn't,CreateMetadataRegistrywraps the existingReflectin a fallback provider. The provider captures five methods, andisProviderForcallsgetOwnMetadataKeyson every lookup. So if some other library put only part of the API onReflect, every metadata lookup throwsTypeError: getOwnMetadataKeys is not a function.To reproduce:
reflect-metadata@0.2.2and@abraham/reflection, which definesdefineMetadatabut notgetOwnMetadataKeys.@abraham/reflectionbeforereflect-metadata.Reflect.getOwnMetadata("a", {}). It throws the error above.With this change, the fallback is only used when all five methods it captures are functions. Otherwise
reflect-metadatainstalls its own implementation, as it does when no metadata API is present. The trade-off is that metadata written through an incomplete implementation beforereflect-metadataloads can't be read afterwards, which is better than failing on every lookup.🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com