How in client-side TypeScript code convert from an actor type to Principal?

How in client-side TypeScript code convert from an actor type to Principal?

Principal.from(anActor) works or no?

Actor.canisterIdOf(actor)

There are some handy utility methods like this and others on the Actor class.

@sea-snake It does not work:

.did file:

type OuterCanister = 
 service {
...
const [outerCanister, outerKey] = this.streams.categoriesTimeOrderSubDB;
/* ... */ Actor.canisterIdOf(outerCanister) /* ... */

Error message:

Argument of type 'OuterCanister' is not assignable to parameter of type 'Actor'.
  Property '[metadataSymbol]' is missing in type 'OuterCanister' but required in type 'Actor'.ts(2345)
actor.d.ts(122, 13): '[metadataSymbol]' is declared here.
const outerCanister: OuterCanister

I have no idea where your variable outerCanister comes from, above only works with actors that were created with Actor.create().

If you have a canister service that’s not an instance of the Actor class but a custom implementation then it falls outside the agent-js lib scope and you’ll need to look into the custom implementation details to see how it’s implemented.

.did file:

type OuterCanister = 
 service {
...
type Streams = 
 record {
   categoriesTimeOrderSubDB: record {
                               OuterCanister;
                               OuterSubDBKey;
                             };
   itemsTimeOrderSubDB: record {
                          OuterCanister;
                          OuterSubDBKey;
                        };
 };
type CanDBPartition = 
 service {
...
   getStreams: (nat) -> (opt Streams) query;
...
 };

Client code:

this.streams = client.getStreams(id)
...
const [outerCanister, outerKey] = this.streams.categoriesTimeOrderSubDB;

So, outerCanister is an actor of the type OuterCanister that is returned by a Candid API (not created by me by Actor.create).

How to convert outerCanister to Principal?

This is because of a bug in agent-js.