<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Id&lt;T&gt;]]></title><description><![CDATA[<p>RE:  &quot;@types/screeps&quot;: &quot;^3.2.1&quot;,</p>
<p>How does  Game.getObjectById<T>(id: Id &lt; T&gt;): T | null; work - how does one construct the id parameter?
the obsolete warning of Game.getObjectById<T>(id: string): T | null; is triggering one's  PSTD;</p>
]]></description><link>http://screeps.com/forum/topic/3088/id-t</link><generator>RSS for Node</generator><lastBuildDate>Tue, 10 Mar 2026 03:53:50 GMT</lastBuildDate><atom:link href="http://screeps.com/forum/topic/3088.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 23 Oct 2020 15:31:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Id&lt;T&gt; on Invalid Date]]></title><description><![CDATA[<p>RE:  &quot;@types/screeps&quot;: &quot;^3.2.1&quot;,</p>
<p>How does  Game.getObjectById<T>(id: Id &lt; T&gt;): T | null; work - how does one construct the id parameter?
the obsolete warning of Game.getObjectById<T>(id: string): T | null; is triggering one's  PSTD;</p>
]]></description><link>http://screeps.com/forum/post/15691</link><guid isPermaLink="true">http://screeps.com/forum/post/15691</guid><dc:creator><![CDATA[AdeptOfNone]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Id&lt;T&gt; on Invalid Date]]></title><description><![CDATA[<p><code>Id&lt;T&gt;</code> is basically an alias of a string. Usually, you can simply replace <code>string</code> with <code>Id&lt;T&gt;</code> wherever you need to.</p>
]]></description><link>http://screeps.com/forum/post/15692</link><guid isPermaLink="true">http://screeps.com/forum/post/15692</guid><dc:creator><![CDATA[JBYoshi]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Id&lt;T&gt; on Invalid Date]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="http://screeps.com/forum/uid/1701">@jbyoshi</a> said in <a href="/forum/post/15692">Id&lt;T&gt;</a>:</p>
<blockquote>
<T>
</blockquote>
<p>How?</p>
]]></description><link>http://screeps.com/forum/post/15695</link><guid isPermaLink="true">http://screeps.com/forum/post/15695</guid><dc:creator><![CDATA[AdeptOfNone]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Id&lt;T&gt; on Invalid Date]]></title><description><![CDATA[<p>The <code>Id&lt;T&gt;</code> type was added to assist situations like this simple example.</p>
<pre><code>interface CreepMemory { 
  sourceId: Id&lt;Source&gt;
}

let source = Game.getObjectById(creep.memory.sourceId)
</code></pre>
<p>In this example, the type of <code>source</code> would be <code>Source</code> (or null) because the type of the game object can be known by the type of the Id.</p>
<p>In this way, you don't need to use something like <code>as Source</code> to type assert it. Consider treating object Ids as something that is typed and not generic strings.</p>
]]></description><link>http://screeps.com/forum/post/15697</link><guid isPermaLink="true">http://screeps.com/forum/post/15697</guid><dc:creator><![CDATA[Pyrodogg]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Id&lt;T&gt; on Invalid Date]]></title><description><![CDATA[<p>OK, let one rephrase one's question.
Imagine one was storing a bunch of id-s, let's say for structures to be maintained, and imagine that this list would include walls and ramparts.<br />
How would one go about invoking the magicks of getObjectById of this list w/o incurring the wrath of tslint (pbuh)?</p>
]]></description><link>http://screeps.com/forum/post/15698</link><guid isPermaLink="true">http://screeps.com/forum/post/15698</guid><dc:creator><![CDATA[AdeptOfNone]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Id&lt;T&gt; on Invalid Date]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="http://screeps.com/forum/uid/2699">@adeptofnone</a> said in <a href="/forum/post/15698">Id&lt;T&gt;</a>:</p>
<blockquote>
<p>tslint</p>
</blockquote>
<p>If I understand your question correctly the best solution would be to store two lists instead of one. First list/array to store all IDs and second list/array to store which structure types each ID belongs to. 1:1 relationship between indexes of both lists will be easy to maintain</p>
]]></description><link>http://screeps.com/forum/post/15700</link><guid isPermaLink="true">http://screeps.com/forum/post/15700</guid><dc:creator><![CDATA[SteelHammer]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Id&lt;T&gt; on Invalid Date]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="http://screeps.com/forum/uid/2699">@adeptofnone</a> said in <a href="/forum/post/15698">Id&lt;T&gt;</a>:</p>
<blockquote>
<p>OK, let one rephrase one's question.
Imagine one was storing a bunch of id-s, let's say for structures to be maintained, and imagine that this list would include walls and ramparts.<br />
How would one go about invoking the magicks of getObjectById of this list w/o incurring the wrath of tslint (pbuh)?</p>
</blockquote>
<p>The <code>T</code> in <code>Id&lt;T&gt;</code> can be a union type. So you can do something like:</p>
<pre><code>let id: Id&lt;StructureWall | StructureRampart&gt;;
let wallOrRampart: StructureWall | StructureRampart | null = Game.getObjectById(id);
</code></pre>
<p>You can read more about union types here: <a href="https://www.typescriptlang.org/docs/handbook/unions-and-intersections.html" rel="nofollow">https://www.typescriptlang.org/docs/handbook/unions-and-intersections.html</a></p>
]]></description><link>http://screeps.com/forum/post/15701</link><guid isPermaLink="true">http://screeps.com/forum/post/15701</guid><dc:creator><![CDATA[Coelso]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Id&lt;T&gt; on Mon, 02 Nov 2020 17:31:17 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="http://screeps.com/forum/uid/1722">@Coelso</a>
Thanks, but calling getObjectById and using the said objects is not the problem. I have a problem with Game.getObjectById(id:string) giving me a warning, for it is marked obsolete. Surely there must be a way for constructing a proper Id<T> parameter for this call from a string + list of known types?</p>
<p><img src="/forum/assets/uploads/files/1604338244593-screenshot-resized.png" alt="0_1604338241978_screenshot.png" class="img-responsive img-markdown" /></p>
<pre><code>  let dismantleObject:Structure&lt;BuildableStructureConstant&gt;|undefined;

            while(target.anchorRoom!.$roomCache.dismantle.ids.length &gt; 0 &amp;&amp; !dismantleObject){
                try{
                    const id = target.anchorRoom!.$roomCache.dismantle.ids.shift()!;
                    dismantleObject = Game.getObjectById(id) as Structure&lt;BuildableStructureConstant&gt;;
                    if (dismantleObject){
                        target.anchorRoom!.$roomCache.dismantle.ids.unshift(id);
                    }
                }catch(e){
                    this.logError(`ERROR ${e}`);
                }
            }

            if (!dismantleObject){
                return;
            }

            worker.moveTo(dismantleObject, {range: 1});
            dismantleObject.notifyWhenAttacked(false);
            const res = worker.dismantle(dismantleObject);
            this.log(`${worker.name} dismantle res:${res}`);</code></pre>
]]></description><link>http://screeps.com/forum/post/15702</link><guid isPermaLink="true">http://screeps.com/forum/post/15702</guid><dc:creator><![CDATA[AdeptOfNone]]></dc:creator><pubDate>Mon, 02 Nov 2020 17:31:17 GMT</pubDate></item><item><title><![CDATA[Reply to Id&lt;T&gt; on Invalid Date]]></title><description><![CDATA[<p>To fix that, you'll want to change the type of <code>$roomCache.dismantle.ids</code>. It looks like it's a <code>string[]</code> right now; if so, I think you need to change that to <code>Id&lt;Structure&lt;BuildableStructureConstant&gt;&gt;[]</code>.</p>
]]></description><link>http://screeps.com/forum/post/15703</link><guid isPermaLink="true">http://screeps.com/forum/post/15703</guid><dc:creator><![CDATA[JBYoshi]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Id&lt;T&gt; on Invalid Date]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="http://screeps.com/forum/uid/1701">@jbyoshi</a> ta</p>
]]></description><link>http://screeps.com/forum/post/15719</link><guid isPermaLink="true">http://screeps.com/forum/post/15719</guid><dc:creator><![CDATA[AdeptOfNone]]></dc:creator><pubDate>Invalid Date</pubDate></item></channel></rss>