在.tsx文件中强制转换时,编译器假定它是JSX,例如:
(<HtmlInputElement> event.target).value
Run Code Online (Sandbox Code Playgroud)
给出错误
JSX元素类型'HtmlInputElement'不是JSX元素的构造函数
你如何在.tsx文件中转换TypeScript ?
TypeScript 2建议使用npm作为类型.在宣言档案的未来.
例子是:
npm install --save @types/lodash
Run Code Online (Sandbox Code Playgroud)
我的问题是应该在应用程序中使用--save-dev,因为TypeScript是否已被转换而未部署?关于这篇文章的一些评论提到了类似的,但我没有看到答案.
也许--save在库中有用,可以在其他人安装你的库时拖动类型?
我错过了其他有用的东西,最佳做法是什么?谢谢.
我想修正警告:
警告:找不到父tsconfig.json
在TypeScript Errors选项卡中IntelliJ IDEA 2016.3.我的TypeScript代码存在于src目录中,我的TypeScript输出lib将按预期进行,src而不会添加文件夹lib.
我lib在其他项目中使用该文件夹,它似乎按预期工作.所以这似乎不是一个大问题,但我偶尔会遇到TSLint的问题,它有时似乎没有拿起.tsx文件是JSX和lint错误,似乎偶尔将其视为普通.ts文件.最终它似乎弄明白了.我想知道这是否与我的TSLint设置配置使用有关tsconfig.json.
我之前已经.js将文件转换成.ts文件src夹中的文件旁边的文件,但是因为我tsconfig.json最近修改了文件.
文件如下:
tsconfig.json
src/index.ts
lib/index.js
lib/index.d.ts
Run Code Online (Sandbox Code Playgroud)
我已经升级到TypeScript 2.1.4,但是看到了2.0.10.
我的tsconfig.json档案:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"jsx": "react",
"allowJs": false,
"isolatedModules": false,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"declaration": true,
"noImplicitAny": false,
"noImplicitUseStrict": true,
"noEmitHelpers": false,
"removeComments": true,
"noLib": false,
"sourceMap": true,
"inlineSources": true, …Run Code Online (Sandbox Code Playgroud) 同
"noImplicitAny": true
Run Code Online (Sandbox Code Playgroud)
TypeScript会给出错误:
参数'x'隐式具有'任意'类型
对于
.do(x => console.log(x));
Run Code Online (Sandbox Code Playgroud)
和错误
','预计
对于:
.do(x: any => console.log(x));
Run Code Online (Sandbox Code Playgroud) 我想知道绑定到ReactiveCommand的推荐方法IsExecuting.
问题是初始命令执行(在构造函数结束时启动)不是使用IsLoading绑定更新WPF控件,尽管后续调用按预期工作.
更新2添加测试绑定代码
这显示了装饰器内容时IsLoading为真
<ac:AdornedControl IsAdornerVisible="{Binding IsLoading}">
<ac:AdornedControl.AdornerContent>
<controls1:LoadingAdornerContent/>
</ac:AdornedControl.AdornerContent>
<fluent:ComboBox
ItemsSource="{Binding Content, Mode=OneWay}"
DisplayMemberPath="Name"
SelectedValuePath="ContentId"
SelectedValue="{Binding SelectedContentId}"
IsSynchronizedWithCurrentItem="True"
/>
</ac:AdornedControl>
Run Code Online (Sandbox Code Playgroud)
更新
我发现了这个:https: //github.com/reactiveui/rxui-design-guidelines
并认为我应该能够做到这样的事情:
this._isLoading = this.WhenAnyValue(x => x.LoadCommand.IsExecuting)
.ToProperty(this, x => x.IsLoading);
Run Code Online (Sandbox Code Playgroud)
但它给出了编译错误:
方法'ReactiveUI.OAPHCreationHelperMixin.ToProperty <TObj,TRet>的类型参数(System.IObservable <TRet>,TObj,System.Linq.Expressions.Expression <System.Func <TObj,TRet >>,TRet,System.Reactive. Concurrency.IScheduler)'无法从用法中推断出来.尝试显式指定类型参数.
我也尝试过:
this._isLoading = this.WhenAnyValue(x => x.LoadCommand.IsExecuting)
.ToProperty<TheViewModel, bool>(this, x => x.IsLoading);
Run Code Online (Sandbox Code Playgroud)
但得到编译错误:
'System.IObservable <System.IObservable <bool >>'不包含'ToProperty'的定义和最佳扩展方法重载'ReactiveUI.OAPHCreationHelperMixin.ToProperty <TObj,TRet>(System.IObservable <TRet>,TObj,System .Linq.Expressions.Expression <System.Func <TObj,TRet >>,TRet,System.Reactive.Concurrency.IScheduler)'有一些无效的参数
和
实例参数:无法从'System.IObservable>'转换为'System.IObservable'
原来下面
我的帖子末尾列出的代码通过访问IsLoading属性来进行初始绑定,听起来就像启动订阅一样.但是从进一步的阅读来看,我似乎应该使用它WhenAny,我似乎无法弄清楚我的鼻子前面放了什么: …
升级到webpack 2我遇到了这个错误:
TypeError:_webpack2.default.optimize.OccurenceOrderPlugin不是函数
运行npm run dev工作正常,但npm run build要创建production构建会styles.css在public构建文件夹中创建一个空文件。
npm run serve 最终得到一个没有样式的网站,因为它导入了空的 styles.css.
我尝试了gatsby-plugin-postcss-sass并gatsby-plugin-sass配置gatsby-config.js如下:
{
resolve: "gatsby-plugin-postcss-sass",
// resolve: "gatsby-plugin-sass",
options: {
includePaths: [
path.resolve(__dirname, './node_modules'),
],
postCssPlugins: [
autoprefixer({
browsers: ['last 2 versions'],
})
]
}
},
Run Code Online (Sandbox Code Playgroud)