ref(attribute): Add type to accept unknown and official attribute type#18201
Merged
s1gr1d merged 2 commits intolms/feat-core-scope-setAttributesfrom Nov 14, 2025
Merged
ref(attribute): Add type to accept unknown and official attribute type#18201s1gr1d merged 2 commits intolms/feat-core-scope-setAttributesfrom
unknown and official attribute type#18201s1gr1d merged 2 commits intolms/feat-core-scope-setAttributesfrom
Conversation
s1gr1d
commented
Nov 14, 2025
| * @returns The typed attribute. | ||
| */ | ||
| export function attributeValueToTypedAttributeValue(value: AttributeValueType): TypedAttributeValue { | ||
| export function attributeValueToTypedAttributeValue(value: unknown): TypedAttributeValue { |
Member
Author
There was a problem hiding this comment.
This can still be typed, but then we would need to typecast in setAttributes where we use the function (which is fine because we already have a bunch of checks).
unknown and official attribute type
Contributor
size-limit report 📦
|
Contributor
node-overhead report 🧳Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.
|
Lms24
approved these changes
Nov 14, 2025
Member
Lms24
left a comment
There was a problem hiding this comment.
Amazing TS work, thank you!
Let's merge this in and go from there.
Lms24
pushed a commit
that referenced
this pull request
Nov 18, 2025
…ype (#18201) Uses a conditional type to infer whether an attribute object has the type of an official attribute by checking if it has a `value` or a `unit`: ```ts export type ValidatedAttributes<T> = { [K in keyof T]: T[K] extends { value: any } | { unit: any } ? ValidAttributeObject : unknown; }; ``` That way, TS can show an error when people attempt to use the attribute type while still allowing non-official types. <img width="673" height="250" alt="image" src="https://github.com/user-attachments/assets/f635f46d-6c3f-49cb-b31f-a02a6ebf91d3" /> --- I also added a small helper type to generate the very long attribute type object, so it can generate a type like this: ```ts /* | { value: string; type: 'string' } | { value: number; type: 'integer' } | { value: number; type: 'double' } */ ```
Lms24
pushed a commit
that referenced
this pull request
Nov 18, 2025
…ype (#18201) Uses a conditional type to infer whether an attribute object has the type of an official attribute by checking if it has a `value` or a `unit`: ```ts export type ValidatedAttributes<T> = { [K in keyof T]: T[K] extends { value: any } | { unit: any } ? ValidAttributeObject : unknown; }; ``` That way, TS can show an error when people attempt to use the attribute type while still allowing non-official types. <img width="673" height="250" alt="image" src="https://github.com/user-attachments/assets/f635f46d-6c3f-49cb-b31f-a02a6ebf91d3" /> --- I also added a small helper type to generate the very long attribute type object, so it can generate a type like this: ```ts /* | { value: string; type: 'string' } | { value: number; type: 'integer' } | { value: number; type: 'double' } */ ```
Lms24
pushed a commit
that referenced
this pull request
Nov 20, 2025
…ype (#18201) Uses a conditional type to infer whether an attribute object has the type of an official attribute by checking if it has a `value` or a `unit`: ```ts export type ValidatedAttributes<T> = { [K in keyof T]: T[K] extends { value: any } | { unit: any } ? ValidAttributeObject : unknown; }; ``` That way, TS can show an error when people attempt to use the attribute type while still allowing non-official types. <img width="673" height="250" alt="image" src="https://github.com/user-attachments/assets/f635f46d-6c3f-49cb-b31f-a02a6ebf91d3" /> --- I also added a small helper type to generate the very long attribute type object, so it can generate a type like this: ```ts /* | { value: string; type: 'string' } | { value: number; type: 'integer' } | { value: number; type: 'double' } */ ```
Lms24
pushed a commit
that referenced
this pull request
Nov 21, 2025
…ype (#18201) Uses a conditional type to infer whether an attribute object has the type of an official attribute by checking if it has a `value` or a `unit`: ```ts export type ValidatedAttributes<T> = { [K in keyof T]: T[K] extends { value: any } | { unit: any } ? ValidAttributeObject : unknown; }; ``` That way, TS can show an error when people attempt to use the attribute type while still allowing non-official types. <img width="673" height="250" alt="image" src="https://github.com/user-attachments/assets/f635f46d-6c3f-49cb-b31f-a02a6ebf91d3" /> --- I also added a small helper type to generate the very long attribute type object, so it can generate a type like this: ```ts /* | { value: string; type: 'string' } | { value: number; type: 'integer' } | { value: number; type: 'double' } */ ```
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.
Uses a conditional type to infer whether an attribute object has the type of an official attribute by checking if it has a
valueor aunit:That way, TS can show an error when people attempt to use the attribute type while still allowing non-official types.
I also added a small helper type to generate the very long attribute type object, so it can generate a type like this: