-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using Generics in an interface, get error TS2322: Type 'string' is not assignable to type 'T'. #10761
Comments
where is the definition of IObservableValue coming from? |
It's from MobX type definition: interface IObservableValue<T> {
get(): T;
set(value: T): void;
intercept(handler: IInterceptor<IValueWillChange<T>>): Lambda;
observe(listener: (newValue: T, oldValue: T) => void, fireImmediately?: boolean): Lambda;
} |
i can not get this to repro. can you provide a self contained sample i could try? |
I created a sample project that repros the issue. MobX not required, only using react. For some reason it wouldn't let me attach the zip to this issue, so I uploaded it here: After extracting the files simply run "npm install" to set up. Then to build with TypeScript 1.8.10 run: "npm run build-1.8" The 1.8.10 build compiles fine, the rc (2.0.2 ) build fails with TS2322. |
Just wondering if you had a chance to try and pull down the sample project zip file and if you were able to reproduce the issue? Let me know if you have any other questions. Thanks. |
@yak77 sorry for the delay, looking now |
This is just a duplicate of #6395 -- it's currently not possible to use a generic class as a JSX element class. A workaround is render(): JSX.Element
{
// Might want to have a generic type alias for this
const StringInput: new() => Input<string> = Input;
return (
<div>
<StringInput val={this._data}/>
</div>
);
} |
@RyanCavanaugh Thanks for looking into this and posting the workaround. Is this a regression in the 2.0 compiler? Because the code I posted compiles with 1.8.10. |
I get the above error using react and mobx in the code below. It may be related to #10589, but could also be a separate cause. The code below compiles successfully with version 1.8.10.
TypeScript Version: 2.0.2 & 2.1.0-dev.20160907
Code
The text was updated successfully, but these errors were encountered: