小编sku*_*ube的帖子

git reset vs git reset HEAD

每次播放文件时,Git都会在您需要取消暂存文件时提供有用的说明:

(use "git reset HEAD <file>..." to unstage)

然而,Atlassian的优秀Git教程简单地说:

git reset <file>

这似乎更直截了当,为什么差异呢?

git git-reset unstage

18
推荐指数
1
解决办法
1万
查看次数

Google Apps脚本:何时使用getActiveSpreadsheet()

我想知道何时使用getActiveSpreadsheet().

我见过很多例子:

var ss = SpreadsheetApp.getActiveSheet();
Run Code Online (Sandbox Code Playgroud)

但我也看到了:

var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
Run Code Online (Sandbox Code Playgroud)

在某些情况下是否隐含了有效的电子表格?

google-apps-script

9
推荐指数
3
解决办法
1万
查看次数

使用Github Web界面或桌面应用程序重置或将Gist恢复为较旧的提交状态

我正在尝试通过Web界面或Github桌面应用程序将Gist回滚到较旧的状态.我见过的解决方案似乎表明了如何使用命令行执行此操作.但是,如果不使用命令行界面,我无法弄清楚如何做到这一点.

CLI是回滚历史记录的唯一方法吗?如果是这样,是否有理由限制Web界面和桌面应用程序?

git gist github revert reset

8
推荐指数
1
解决办法
2136
查看次数

元素隐式地具有“ any”类型,因为索引表达式不是“ number”类型[7015]

我已经从David Walsh的css动画回调中获取了代码,并将其修改为TypeScript。但是,我遇到错误,不知道为什么:

interface IBrowserPrefix {
  [key: string]: string;
}

// http://davidwalsh.name/css-animation-callback
function whichAnimationEvent() {
  let x: keyof IBrowserPrefix;
  const el = document.createElement('temp');
  const browserPrefix: IBrowserPrefix = {
    animation: 'animationend',
    OAnimation: 'oAnimationEnd',
    MozAnimation: 'animationend',
    WebkitAnimation: 'webkitAnimationEnd',
  };

  for (x in browserPrefix) {
    if (el.style[x] !== undefined) {
    //           ^---- [TS Error]: Element has 'any' type b/c index expression is not of type 'number'
      return browserPrefix[x];
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

javascript typescript

7
推荐指数
1
解决办法
8515
查看次数

“...”类型的参数不能分配给“...”类型的参数 TS 2345

鉴于以下情况:

interface MyInterface {
  type: string;
}

let arr: object[] = [ {type: 'asdf'}, {type: 'qwerty'}]

// Alphabetical sort
arr.sort((a: MyInterface, b: MyInterface) => {
      if (a.type < b.type) return -1;
      if (a.type > b.type) return 1;
      return 0;
    });
Run Code Online (Sandbox Code Playgroud)

有人可以帮助破译 TS 错误:

// TypeScript Error
[ts]
Argument of type '(a: MyInterface, b: MyInterface) => 0 | 1 | -1' is not assignable to parameter of type '(a: object, b: object) => number'.
  Types of parameters 'a' and 'a' are …
Run Code Online (Sandbox Code Playgroud)

typescript

7
推荐指数
1
解决办法
2万
查看次数

Flexbox'空间介于'之间'无法在IE11中运行

我正在尝试使用flexbox将内容与顶部和底部对齐.看起来它应该很简单,但我不能让它在IE11中工作.有什么想法/建议吗?

.wrap {
  display: flex;
  flex-direction: column;
  min-height:100vh;
  justify-content: space-between;
}
Run Code Online (Sandbox Code Playgroud)
<div class="wrap">
  <div class="top">Top</div>
  <div class="bottom">Bottom</div>
</div>
Run Code Online (Sandbox Code Playgroud)

css internet-explorer css3 flexbox internet-explorer-11

5
推荐指数
0
解决办法
4577
查看次数

在jsFiddle中使用模块和控制器的简单AngularJS示例

这可能是一个组合jsFiddle/Angular问题,但我正在尝试向我学习一些基本的Angular,我不确定为什么它只在我在HTML窗格中包含控制器JS时才有效. jsFiddle在这里

基本上以下工作:

<div ng-app="myAppModule" ng-controller="someController">
<!-- Show the name in the browser -->
 <h1>Welcome {{ name }}</h1>

<p>made by : {{userName}}</p>
<!-- Bind the input to the name -->
<input ng-model="name" name="name" placeholder="Enter your name" />
</div>
<script>
var myApp = angular.module('myAppModule', []);
myApp.controller('someController', function($scope) {
    // do some stuff here
    $scope.userName = "skube";
});
</script>
Run Code Online (Sandbox Code Playgroud)

但是,如果我尝试将脚本标记中的JS移动到JavaScript窗格,则会失败.

javascript jsfiddle angularjs

3
推荐指数
1
解决办法
1万
查看次数

在React中使用全局SASS变量迁移到样式化组件

我试图将Styled-Components缓慢引入现有的代码库中,该代码库严重依赖于全局SASS变量(部分导入到中main.scss)。

如何引用SCSS变量?以下内容不起作用:

import React from 'react';
import styled from 'styled-components';

const Button = styled.button`
  background-color: $color-blue;
`;

export default Button;
Run Code Online (Sandbox Code Playgroud)

我是从错误的方式来处理这个问题吗?

sass reactjs styled-components

3
推荐指数
3
解决办法
3965
查看次数

打开和关闭对话框模式并等待通过提供程序的响应

使用 React 测试库来测试对话框提供程序。我可以让它打开,并在它出现时断言 - 但由于某种原因我无法在测试中关闭它。我需要重新渲染吗?

test('await the closing or confirming of the modal', async () => {
  const { debug, getByText, queryByText } = render(
    <DialogProvider>
      <Test />
    </DialogProvider>,
  );
  const openDialogButton = getByText(/click me/i);
  fireEvent.click(openDialogButton);
  await wait(() => getByText(/ok/i));
  fireEvent.click(getByText(/ok/i));
  debug();
});


function Test() {
  const confirm = useConfirmation();
  return (
    <button
      onClick={() => {
        confirm({ variant: 'info' });
      }}
    >
      click me
    </button>
  );
}
Run Code Online (Sandbox Code Playgroud)

unit-testing reactjs react-testing-library

3
推荐指数
1
解决办法
6451
查看次数

什么是"反应/没有未使用状态",为什么它不好?

有人可以解释究竟是什么no-unused-state意思,为什么它被认为是不好的做法?

我似乎无法找到除了从提交中获取的以下句子之外的任何信息:

这会添加一个新规则react/no-unused-state,它会发现React组件中的状态字段,并警告它们是否永远不会被读取.

reactjs eslint

1
推荐指数
1
解决办法
3161
查看次数

如何在 React Router 中使用 Typescript 并进行匹配

该方法

我正在尝试了解 Typescript 和 React Router。我一直在挣扎...

我目前收到错误:

属性 'params' 不存在于类型 'RouteComponentProps<{}, StaticContext, any>'.ts(2339)"`

import React from "react";
import { RouteComponentProps } from "react-router-dom";

const TopicDetail = ({ match }: { match: RouteComponentProps }) => {
  return (
    <div>
      <h3>{match.params.topicId}</h3>
                 ~~~~~~
    </div>
  );
};

export default TopicDetail;
Run Code Online (Sandbox Code Playgroud)

看,没有错误!

可以通过定义自己的来消除错误interface,但我觉得这是错误的方法:

import React from "react";

interface Props {
  params: any;
}
const TopicDetail = ({ match }: { match: Props }) => {
  return (
    <div>
      <h3>{match.params.topicId}</h3>
    </div>
  ); …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs react-router

1
推荐指数
1
解决办法
2648
查看次数