小编Jon*_*man的帖子

库未加载:/usr/local/opt/readline/lib/libreadline.7.dylib撞毁我的rails控制台

当我尝试运行时,rails console我收到此错误:

/Users/TuzsNewMacBook/.rvm/gems/ruby-2.3.7/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require':
 dlopen(/Users/TuzsNewMacBook/.rvm/rubies/ruby-2.3.7/lib/ruby/2.3.0/x86_64-darwin18/readline.bundle, 9): 
Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib (LoadError)
Run Code Online (Sandbox Code Playgroud)

快速搜索让我看到这篇文章,我尝试了一些事情:

brew reinstall postgresql (这确实是这个项目的数据库)

cd /usr/local/opt/readline/lib    
ln libreadline.8.0.dylib libreadline.6.2.dylib
Run Code Online (Sandbox Code Playgroud)

(我的readline版本是8)

brew link readline --force

但这些都没有解决它.

我最近添加了pry-coolline,guard并且guard-livereloadgems到我的项目,如果这有任何区别(rails控制台在那之前加载好).我正在使用最新的macos.

(更新)我使用pry rails作为我的rails控制台,如果这有任何区别.

有帮助吗?谢谢.

ruby-on-rails libreadline

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

Jest.js 错误:“已接收:序列化为相同的字符串”

我在这个测试中遇到了一个奇怪的问题:

交易.test.js

import Deal from "../src/models/Deal";
import apiProducts from "../__mocks__/api/products";

describe("Deal", () => {
  describe("Deal.fromApi", () => {
    it("takes an api product and returns a Deal", () => {
      const apiDeal = apiProducts[0];
      const newDeal = Deal.fromApi(apiDeal);
      const expected = expectedDeal();
      expect(newDeal).toEqual(expected);
    });
  });
});
Run Code Online (Sandbox Code Playgroud)

交易.js

export default class Deal {
  // no constructor since we only ever create a deal from Deal.fromApi

  static fromApi(obj: Object): Deal {
    const deal = new Deal();
    deal.id = obj.id;
    deal.name = obj.name;
    deal.slug …
Run Code Online (Sandbox Code Playgroud)

javascript unit-testing jestjs

52
推荐指数
6
解决办法
5万
查看次数

ESLint:'cy' 未定义(赛普拉斯)

我刚刚开始在我的 React Typescript 项目中使用 Cypress。我有一些简单的测试要运行:

describe('settings page', () => {
  beforeEach(() => {
    cy.visit('http://localhost:3000')
  });
  it('starts in a waiting state, with no settings.', () => {
    cy.contains('Waiting for settings...')
  });
  it('shows settings once settings are received', () => {
    const state = cy.window().its('store').invoke('getState')
    console.log(state) // different question: how do I get this to be the state and not a $Chainer?
  });
});
Run Code Online (Sandbox Code Playgroud)

它在 Cypress 中运行得很好。但是我在 Webstorm 中收到 Typescript 错误,说cy没有定义(TS 和 ESlint 错误)和describeall files must be …

reactjs eslint cypress

41
推荐指数
9
解决办法
2万
查看次数

更新后导致编译错误

我只是跑pod update我的应用程序,而现在它不会编译,从赋予这些问题LinkShareContent.swiftFacebookShare.

Cannot assign to property: 'contentDescription' is a get-only property
Cannot assign to property: 'contentTitle' is a get-only property
Cannot assign to property: 'imageURL' is a get-only property
Run Code Online (Sandbox Code Playgroud)

这些是我的pod更新中与Facebook相关的行:

Installing FBSDKCoreKit 4.23.0 (was 4.22.0)
Installing FBSDKLoginKit 4.23.0 (was 4.22.0)
Installing FBSDKShareKit 4.23.0 (was 4.22.0)
Using FacebookCore (0.2.0)
Using FacebookLogin (0.2.0)
Using FacebookShare (0.2.0)
Run Code Online (Sandbox Code Playgroud)

有谁知道这个问题?我做错什么了吗?

facebook cocoapods swift

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

赛普拉斯在玩笑断言中导致类型错误

我一直在使用react-testing-library,以及@testing-library/jest-dom/extend-expect。我昨天安装了 Cypress,现在我所有的玩笑匹配器都收到 Typescript 错误:

Property 'toEqual' doesn't exist on type 'Assertion'. Did you mean 'equal'?

看起来它是expect从错误的断言库中获取类型的?此外,expect(...).to.equal(...)甚至都不起作用。

我实际上尝试安装@types/jest,纱线似乎已经成功,但它没有列在我package.jsondevDependencies.

这是我的 tsconfig

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "noImplicitAny": false,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": false,
    "noEmit": true,
    "jsx": "react",
    "skipDefaultLibCheck": true,
    "types": [
      "node",
      "cypress",
      "jest"
    ]
  },
  "include": …
Run Code Online (Sandbox Code Playgroud)

typescript jestjs cypress

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

无法读取未定义的属性“方向”,仅测试

我刚刚添加TouchableOpacity到一个组件,应用程序运行良好,但我的测试,使用react-native-testing-library,无法运行:

  ? Test suite failed to run

    TypeError: Cannot read property 'Direction' of undefined

      at Object.Direction (node_modules/react-native-gesture-handler/Directions.js:3:39)
      at Object.<anonymous> (node_modules/react-native-gesture-handler/GestureHandler.js:2:1)
Run Code Online (Sandbox Code Playgroud)

我刚刚删除并重新添加react-native-gesture-handler了纱线,然后运行pod install. 同样,应用程序正在运行,但测试无法运行。

我实际上在使用<Text onPress={() => onOptionPress(opt)} />而不是TouchableOpacity.

成分:

const SelectOptions = ({ field, dismissOverlay, onOptionPress }) => {
  return (
    <Overlay
      isVisible
      overlayStyle={styles.overlay}
      height={"auto"}
      onBackdropPress={dismissOverlay}
    >
      <View>
        {field.options.map((opt, i) => (
          <TouchableOpacity
            style={styles.option}
            key={i}
            onPress={() => onOptionPress(opt)}
          >
            <Text>{opt}</Text>
          </TouchableOpacity>
        ))}
      </View>
    </Overlay>
  );
};
Run Code Online (Sandbox Code Playgroud)

测试:

describe("CardFormView", …
Run Code Online (Sandbox Code Playgroud)

react-native

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

Redux 工具包中多个切片中的操作

Redux 工具包文档提到在多个减速器中使用操作(或者更确切地说是操作类型)

首先,Redux 操作类型并不意味着专用于单个切片。从概念上讲,每个切片缩减器“拥有”自己的 Redux 状态片段,但它应该能够侦听任何操作类型并适当地更新其状态。例如,许多不同的切片可能希望通过清除数据或重置回初始状态值来响应“用户注销”操作。在设计状态形状和创建切片时请记住这一点。

但是,“记住这一点”,鉴于工具包将切片名称放在每个动作类型的开头,实现这一目标的最佳方法什么?并且您从该切片导出一个函数并调用该单个函数来分派动作?我错过了什么?这是否必须以某种不使用的方式完成createSlice

redux redux-toolkit

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

类型“any”不可分配给类型“never”

我正在使用(我认为)“索引访问参数”来写入我的减速器中的对象:

export type SettingsState = {
    brainRadiusEstimate: number,
    displayProgressIndicator: boolean,
    respiratoryFilterUpperBound: string,
    patientFeedback: PatientFeedbackType,
    connectionStatus: ConnectionStatus,
    brainSize: BrainSize,
    version: 'BETA 2',
}

export type ChangeParameterAction = {
    type: 'CHANGE_PARAMETER',
    parameter: ParameterName,
    value: any
}


export default function settingsReducer(state: SettingsState = defaultState, action: ChangeParameterAction): SettingsState {
  switch (action.type) {
    case 'CHANGE_PARAMETER':
      const newState: SettingsState = { ...state };
      newState[action.parameter] = action.value;
      return newState;
    default:
      return state;
  }
}
Run Code Online (Sandbox Code Playgroud)

我收到一条错误newState[action.parameter] = action.value消息“类型‘any’不可分配给类型‘never’”。

在这里(在“对索引访问类型的不健全写入的修复”下)看到,这确实是 TypeScript 中所期望的。它说解决方案是“如果您确信自己没有处理错误,则可以使用类型断言”。

我尝试过添加

type ValueTypes …
Run Code Online (Sandbox Code Playgroud)

typescript redux

10
推荐指数
2
解决办法
4万
查看次数

Date.prototype.toLocaleDateString() 中的选项类型错误

以下代码导致 TypeScript 错误,但工作正常:

components.push(expirationDate.toLocaleDateString(undefined, { dateStyle: 'long' }));

Error:(31, 74) TS2345: Argument of type '{ dateStyle: string; }' is not assignable to parameter of type 'DateTimeFormatOptions'.
  Object literal may only specify known properties, and 'dateStyle' does not exist in type 'DateTimeFormatOptions'.
Run Code Online (Sandbox Code Playgroud)

我确实看到dateStyle确实没有包含在Intl.DateTimeFormatOptions(这是选项对象的类型:

    toLocaleDateString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
    ...
    interface DateTimeFormatOptions {
        localeMatcher?: string;
        weekday?: string;
        era?: string;
        year?: string;
        month?: string;
        day?: string;
        hour?: string;
        minute?: string;
        second?: string;
        timeZoneName?: string;
        formatMatcher?: string;
        hour12?: …
Run Code Online (Sandbox Code Playgroud)

typescript

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

字典参数的类型注释

我可以为 python 中的函数参数指定特定的字典形状/形式吗?

就像在打字稿中一样,我指示info参数应该是带有字符串name和数字的对象age

function parseInfo(info: {name: string, age: number}) { /* ... */ }
Run Code Online (Sandbox Code Playgroud)

有没有办法用 python 函数来做到这一点,否则:

def parseInfo(info: dict):
  # function body
Run Code Online (Sandbox Code Playgroud)

或者这可能不是Pythonic,我应该使用命名关键字或类似的东西?

python

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