imgen
imgen

Reputation: 3123

generic function call in typescript throws error

I have certain code that looks like this

interface KnockoutObservableArrayStatic {
    fn: KnockoutObservableArrayFunctions<any>;
    <T>(value?: T[]): KnockoutObservableArray<T>;
}
declare var ko: KnockoutObservableArrayStatic;

I want to create a empty observable array with type TElement, which should be something like this

var elementArray: TElement[] = null;
var observableArray = ko(elementArray);

But compiler gives me error

Cannot convert 'KnockoutObservableArray' to 'KnockoutObservableArray': Call signatures of types 'KnockoutObservableArray' and 'KnockoutObservableArray' are incompatible

How come?

Upvotes: 0

Views: 279

Answers (2)

onets
onets

Reputation: 91

I had the same problem when compiled solution in VS2013.

I deleted this two lines from MyProject.csproj file

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets')" />

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props')" />

and errors went out.

Upvotes: 0

Ryan Cavanaugh
Ryan Cavanaugh

Reputation: 220884

Hard to say without seeing all of the code, but this sounds like a compiler bug (you shouldn't see "Cannot convert T to T" errors ever, basically). If you could post an issue with a self-contained example I can verify if the code compiles with the latest TypeScript compiler. There have been several bugs around generic compatibility with the Knockout type structure like this.

Upvotes: 3

Related Questions