initialState出现错误:类型为'{email:string; 密码:字符串;有效:布尔值;}'不可分配给'never'类型的参数。ts(2345)
function reducer(state: IState, action: IFluxAction) {
const Users = UsersFetch()
switch (action.type) {
case 'email':
const email = action.value
const valid = Users.find(e => e === email) ? true : false
return {
email,
valid,
}
case 'password':
const password = action.value
return {
password,
}
default:
throw new Error()
}
}
Run Code Online (Sandbox Code Playgroud)
const initialState = {
email: '',
password: '',
valid: false,
}
const [state, dispatch] = React.useReducer(reducer, initialState)
Run Code Online (Sandbox Code Playgroud)
键入此错误以满足错误的正确方法是什么?
React 16.8.1 打字稿3.3.1
应该(通过固定)
添加...state到收益中,例如 …
我有一个触发通道事件'countIncr'的变体,但是我看不到活动有效负载对应的活动订阅事件。
更新:我对此发布内容进行了一些更新,现在我更改标题以更代表我的位置。
我收到了graphqlPlayground错误
"Subscription field must return Async Iterable. Received: undefined"
Run Code Online (Sandbox Code Playgroud)
TGRstack复制我遇到了麻烦: https : //github.com/TGRstack/tgr-apollo-subscription-example-microservice/
在没有TGRstack的情况下进行工作复制: https : //github.com/Falieson/fullstack-apollo-subscription-example
前端:https:
//github.com/TGRstack/tgr-apollo-subscription-example-microservice/blob/master/counter-ui/src/app/routes/Home/HomePage.tsx
const COUNTER_SUBSCRIPTION = gql`
subscription onCountIncr {
count
}
`
const Counter = () => (
<Subscription
subscription={COUNTER_SUBSCRIPTION}
>
{({ data, loading }) => {
console.log({loading, data})
return loading
? <h1>Loading ...</h1>
: data.count
? <h2>Counter: {data.count}</h2>
: <h1>Counter Subscription Not Available</h1>
}}
</Subscription>
)
Run Code Online (Sandbox Code Playgroud)
BE解析器:https : //github.com/TGRstack/tgr-apollo-subscription-example-microservice/blob/master/counter-service/src/gql/Resolvers.ts
是模式:https : //github.com/TGRstack/tgr-apollo-subscription-example-microservice/blob/master/counter-service/src/gql/Schema.ts
BE控制器:https://github.com/TGRstack/tgr-apollo-subscription-example-microservice/blob/master/counter-service/src/gql/Counter.ts …
我已经安装了@ types/react-dom以及typescript和@ types/react以及@ types/meteor但是当我尝试从命令行运行typechecker时我收到以下错误
您可以重现错误并在此处查看我的所有配置:https://github.com/Falieson/react15-meteor1.5
谢谢你的帮助!
$ meteor npm run type:client
> react-meteor-example@0.1.0 type:client /Users/sjcfmett/Private/ReactMeteorExample
> tslint -p ./tsconfig.json --type-check './client/**/*.{ts,tsx}'
Error at node_modules/@types/react-dom/node_modules/@types/react/index.d.ts:3422:13: Subsequent variable declarations must have the same type. Variable 'a' must be of type 'DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>', but here has type 'DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>'.
Error at node_modules/@types/react-dom/node_modules/@types/react/index.d.ts:3423:13: Subsequent variable declarations must have the same type. Variable 'abbr' must be of type 'DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>', but here has type 'DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>'.
Error at node_modules/@types/react-dom/node_modules/@types/react/index.d.ts:3424:13: Subsequent variable declarations …Run Code Online (Sandbox Code Playgroud) 对于流星1.3知识渊博的人来说,这可能是一个非常简单的问题.
在流星应用程序结构文档中,建议将API拆分为几个文件,但我没有看到任何如何将它们重新组合在一起的示例.我开始用藤阵营教程:收藏,我试图分裂/api/tasks.js成
tasks.js methods.js server/publications.js
我不知道我需要从tasks.js中的代码做出哪些更改才能正确导入移动到methods.js和server/publications.js的代码
谢谢您的帮助!
代码:http://www.github.com/Falieson/LearningReact/blob/meteor_todos/MeteorTodos_React/imports/api/tasks/tasks.js
我已经分叉了 react-flexbox-grid 来添加对隐藏列的支持(这是我第一次贡献),但我无法在我的项目中包含该包。
根据文档:Git Urls as Dependencies,我将以下内容放入我的 package.json 中:
"react-flexbox-grid": "falieson/react-flexbox-grid#hidden-columns",
Run Code Online (Sandbox Code Playgroud)
运行 npm i 后,我看到 npm 已获取并且安装包没有错误。
???反应 dom@15.4.1 ??? react-flexbox-grid@0.10.2 (git://github.com/falieson/react-flexbox-grid.git#f8e9e9053430b619f4c7fd79b90ccd4f44d6a05c) ??? react-fontawesome@1.5.0
但是当我启动服务器时meteor:webpack 抱怨:
./imports/ui/Home/index.jsx 中的错误未找到模块:错误:无法解析 /Users/falieson/Code/planetx-boilerplate/imports/ui/Home 中的模块“react-flexbox-grid”
我没有更改 index.jsx 上的任何内容
import {Grid, Row, Col} from 'react-flexbox-grid';
Run Code Online (Sandbox Code Playgroud)
这是我的流星 webpack 配置:
{
"css": {
"module": true
},
"module": {
"loaders": [
{
"test": "/\\.css$/",
"loader": "style!css?modules",
"include": "/flexboxgrid/"
}
]
}
}
Run Code Online (Sandbox Code Playgroud) 该表单用于向项目添加项目,但项目不会删除!更糟糕的是,任何更新都会复制所有嵌套表单(1x2 = 2,然后下一次更新会为每个更新4等)
应用程序/管理/ project.rb
ActiveAdmin.register Project do
permit_params :title, :description, :git_url, :demo_url, :version, :lastpublished, :firstpublished,
project_features_attributes: [:project_id, :description, :_destroy => true],
project_mentions_attributes: [:project_id, :title, :url, :published, :_destroy => true]
form do |f|
f.semantic_errors *f.object.errors.keys
f.inputs
f.buttons
end
form do |f|
f.inputs "Project Details" do
f.inputs :title
f.inputs :description
f.inputs :git_url, :default => "http://github.com/"
f.inputs :demo_url
f.inputs :version
f.inputs :firstpublished
f.inputs :lastpublished
f.inputs do
f.has_many :project_features,
:allow_destroy => true,
:heading => 'Features' do |cf|
cf.input :description
end
end
f.inputs do …Run Code Online (Sandbox Code Playgroud) 有一个包含许多javascript标签的大型html文件.我正在尝试挖出该变量的内容.变量名保持不变,但每个请求的内容都会更改.
examplefile.html
<script type="text/javascript">//.... more js</script>
<script type="text/javascript">//.... more js</script>
<script type="text/javascript">var foo = {"b":"bar","c":"cat"}</script>
<script type="text/javascript">//.... more js</script>
<script type="text/javascript">//.... more js</script>
<script type="text/javascript">//.... more js</script>
Run Code Online (Sandbox Code Playgroud)
想要的控制台结果
> var result = $('script').<some_selection_thingy>
result = {"b":"bar","c":"cat"}
Run Code Online (Sandbox Code Playgroud)
让我解释一下......我的意思是我的问题是 - a)如何选择具有内容'var foo'的数组对象b)如何获取var foo变量的内容以便我可以将该信息导入到本地json变量中以进行进一步处理.
当你在控制台中运行$('script')时,jquery返回一个数组.
> $('script')
[<script type="text/javascript">//.... more js</script>,<script type="text/javascript">//.... more js</script>,<script type="text/javascript">var foo = {"b":"bar","c":"cat"}</script>,<script type="text/javascript">...</script>]
Run Code Online (Sandbox Code Playgroud)
因为这是cheerio实际上并不是jquery,所以dom没有加载所以我不能只做$(foo). 有一个替代方案,我可以使用jsdom而不是cheerio,但我已经读过其他stackoverflow响应(在研究这个问题时),它的性能较差,所以我更愿意学习正确的jquery选择器,我需要挖出这个变量.
server.js
// some cheerio node code
url = 'someurl';
request(url, function(error, response, html){
var $ = cheerio.load(html);
result = $('script').map(&:text).select{ |s| s['var …Run Code Online (Sandbox Code Playgroud) 我已经使用 TS 一年多了,但我仍然对导入和导出有些困惑。为什么我不能将我导入到导出对象中的对象展开?
/// file1
export {
PORT,
SSL_CRT,
SSL_KEY,
}
Run Code Online (Sandbox Code Playgroud)
// file2
import * as env from 'file1'
// env.PORT is available at this point
export {
...env // [ts] Identifier expected. [1003]
}
Run Code Online (Sandbox Code Playgroud)
我用以下方法解决了这个问题,但我知道它不一样,也不是我想要的。
// file2
import * as env from 'file1'
export default {
...env // [ts] Identifier expected. [1003]
}
Run Code Online (Sandbox Code Playgroud) typescript ×4
javascript ×3
meteor ×3
reactjs ×3
node.js ×2
activeadmin ×1
apollo ×1
cheerio ×1
ecmascript-6 ×1
graphql ×1
jquery ×1
nested-forms ×1
open-source ×1
react-dom ×1
webpack ×1