Axel Rauschmayer on Nostr: #TypeScript: Is it possible to create an object that is assignable to the following ...
#TypeScript: Is it possible to create an object that is assignable to the following type (without using `as`)?
type Obj = {
readonly sym: unique symbol,
};
const SYM: unique symbol = Symbol('SYM');
const obj: Obj = {
sym: SYM,
// Type 'typeof SYM' is not assignable to type 'typeof sym'.
};
Published at
2025-02-16 18:39:13 UTCEvent JSON
{
"id": "e3df4333e9908676d3aae9d4d841614420285323685aefc64e03bc6ec21fb478",
"pubkey": "7a7a0978cc46ef7fd548fb125e51c04de7d4ca639417a21b56aa95e3711c0b38",
"created_at": 1739731153,
"kind": 1,
"tags": [
[
"t",
"typescript"
],
[
"proxy",
"https://fosstodon.org/@rauschma/114015020903037888",
"web"
],
[
"proxy",
"https://fosstodon.org/users/rauschma/statuses/114015020903037888",
"activitypub"
],
[
"L",
"pink.momostr"
],
[
"l",
"pink.momostr.activitypub:https://fosstodon.org/users/rauschma/statuses/114015020903037888",
"pink.momostr"
],
[
"-"
]
],
"content": "#TypeScript: Is it possible to create an object that is assignable to the following type (without using `as`)?\n\ntype Obj = {\n readonly sym: unique symbol,\n};\n\nconst SYM: unique symbol = Symbol('SYM');\nconst obj: Obj = {\n sym: SYM,\n // Type 'typeof SYM' is not assignable to type 'typeof sym'.\n};",
"sig": "1e13c3f93a70ea265cb7a81174fec655d0b3b22f3a307de6fc281f24a88d9c56fbe84937d931685051d746130ed19fb4a13ef6cb29708be96dd7ef2f484a0d1f"
}