Scott Nimrod
Scott Nimrod

Reputation: 11595

How do I declare a type parameter that derives from a specific class?

How do I declare a type parameter that derives from a specific class?

I'm attempting to do the following:

let registerTable (T:EntityData) (client:IEasyMobileServiceClient) =
    client.RegisterTable<T>(); client

However, this results in the following error:

Error The type 'T' is not defined

Here's the signature for RegisterTable:

abstract member RegisterTable : unit -> unit when 'A :> EntityData

Upvotes: 0

Views: 56

Answers (1)

Scott Nimrod
Scott Nimrod

Reputation: 11595

Given EntityData is the type my generic needs to derive from:

let registerTable<'T when 'T :> EntityData> (client:IEasyMobileServiceClient) =
    client.RegisterTable<'T>(); client

The caller can look like this:

registerTable<TodoItem>

Upvotes: 2

Related Questions