小编use*_*932的帖子

带有打字稿的 nextjs API,将 NextApiRequest 查询参数限制为字符串类型

在此端点处理程序中,有没有一种方法可以将req.queryNextJS限制NextApiRequest为仅string类型而不是string | string[]. 例如,someQueryParam这里是string | string[]类型,但我想将其用作string类型

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse<Response>
) {

   const { someQueryParam } = req.query;
   
   // pass in someQueryParam as a string into a function call
   const result = functionCall(someQueryParam)
}
Run Code Online (Sandbox Code Playgroud)

string将 someQueryParam 传递到仅接受参数类型的函数时出现打字稿错误:

Argument of type 'string | string[]' is not assignable to parameter of type 'string'.
  Type 'string[]' is not assignable to type 'string'.
Run Code Online (Sandbox Code Playgroud)

NextApiRequest …

typescript next.js

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

如何从Google Apps脚本连接到Facebook Graph API?

我正在尝试通过Google Apps脚本连接到Facebook Graph API,但我收到了错误消息

我试过了:

function myFunction (name) {

  FB.init({  
    appId      : '{your-app-id}',  
    status     : true,  
    xfbml      : true,  
    version    : 'v2.0'   
  });  

  var jsonData = UrlFetchApp.fetch("graph.facebook.com/"; + name);
}
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

function myFuntion(name) {  

    window.fbAsyncInit = function() {  
        FB.init({  
          appId      : 'your-app-id',  
          xfbml      : true,  
          version    : 'v2.0'  
        });  
      };   

      var jsonData = UrlFetchApp.fetch("graph.facebook.com/"; + name);

}
Run Code Online (Sandbox Code Playgroud)

但是没有工作,我总是得到:

"ReferenceError:"FB"未定义." 并且"ReferenceError:"窗口"未定义"

"(#4)达到应用程序请求限制","类型":"OAuthException","code":4}}

尽管将我的Facebook应用程序ID放入变量中.我知道"窗口"是外部JavaScript库的一部分,这就是为什么我无法在Google Apps脚本中使用它,但即使在查看其他帖子之后我仍然对为什么我得到"FB"感到困惑没有定义错误.

关于如何解决这个问题的任何想法?

google-sheets google-apps-script facebook-graph-api-v2.0

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

防止 gmail 剥离 href、target 和 id 属性

我正在使用 Mailgun 从我的 NodeJS 服务器向 Gmail 帐户发送一封电子邮件,但 Gmail 删除了电子邮件中的所有属性。这是什么原因,我如何防止这种情况发生?我尝试使用 encodeURIComponent 对 href 值进行编码,但这对 href 标记没有任何作用。我也没有使用任何 CSS 或任何东西,所以我很困惑为什么会发生这种情况。

前:

<a href="/resetpw" id="reset-link" id="reset" target="_blank">Reset Password</a>
Run Code Online (Sandbox Code Playgroud)

之后(当我检查电子邮件的 HTML 时):

<a></a>
Run Code Online (Sandbox Code Playgroud)

javascript gmail mailgun

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

反应钩子测试库的状态改变后,如何测试组件是否重新渲染

我正在使用https://github.com/testing-library/react-hooks-testing-library来测试我的组件,但不确定如何检查我的组件在此测试中的状态更改后是否已重新渲染

const { container, getAllByText, getAllByRole, queryByLabelText, getByText, getByLabelText } = renderNavBar(
    initialState,
    dispatchMock,
);

// get all divs
let divs = getAllByRole('div');
.
.
.

const { result, waitForNextUpdate } = renderHook(() => useReducer(Reducer, initialState));
const [ , dispatch ] = result.current;

act(() => {
    dispatch({ type: 'SET_ACTIVE_LINK', payload: 'about' });
    fireEvent.click(getByText('home'));
});


// get all divs after the state change,
divs = getAllByRole('div');  // <---- this still has the NavBar component with the old state

Run Code Online (Sandbox Code Playgroud)

状态在 …

javascript testing unit-testing reactjs react-testing-library

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

tailwind 3.0.23 类未在故事书中实时应用

无法通过 Storybook UI 实时应用 Tailwind 类,例如,通过classes这里的 props 更改按钮的颜色从bg-red-600bg-red-100不会改变 Storybook ui 中按钮的颜色,是否可以更改用户界面中的按钮看看它会是什么样子?(组件在应用程序中按预期工作,只是不在故事书中工作)

不确定这是否与清除或 JIT 编译有关https://github.com/tailwindlabs/tailwindcss/discussions/6347

storybook ui

在此输入图像描述

button component

<button
      type="button"
      className={clsx(
        "rounded-full py-2 px-3",
        classes,
        disabled ? "disabled:opacity-25" : ""
      )}
      onClick={onClick}
    >
Run Code Online (Sandbox Code Playgroud)

tailwind.config.js

module.exports = {
  content: [
    "./pages/**/*.{js,ts,jsx,tsx}",
    "./components/**/*.{js,ts,jsx,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
};
Run Code Online (Sandbox Code Playgroud)

button.stories.tsx

ButtonComponent.args = {
  label: "Button",
  classes: "bg-red-600",
  disabled: false,
};
Run Code Online (Sandbox Code Playgroud)

preview.js

import "!style-loader!css-loader!postcss-loader!tailwindcss/tailwind.css";
import "../styles/globals.css";

export const parameters = {
  actions: { …
Run Code Online (Sandbox Code Playgroud)

reactjs postcss next.js storybook tailwind-css

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

在 CSS 中悬停时更改 Ionic 列表项的背景颜色

我正在将 Ionic 框架用于移动 Web 应用程序。我试图在悬停时更改 Ionic 列表项的背景颜色,但它不会改变。

这是我的 html 中的内容:

        <ion-list>
            <ion-item ng-repeat="item in items" href="#/newpage">               
                <div>{{item.color}}</div>                       
            </ion-item>
        </ion-list>
Run Code Online (Sandbox Code Playgroud)

这是 CSS 中的内容:

ion-item:hover {

    background-color: red;
    border-color: red;
}
Run Code Online (Sandbox Code Playgroud)

边框颜色类型有效,但它只突出显示项目的左、上、右边框,而不是下边框。悬停时背景颜色根本不会改变。ion-item 中的 href 标签是否有可能禁用 CSS?如果我删除 href 标签,它工作正常。

我在网上寻求帮助,但没有找到解决此问题的方法或解释。任何帮助表示赞赏。谢谢。

html css angularjs ionic-framework

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

在Linux上将anaconda安装到家中的不同文件夹中

我想将Anaconda安装到不同的路径,例如我的linux服务器上的/ opt,但我一直收到ERROR:文件或目录已经存在:/ opt,即使那里没有文件或目录.它不会让我安装,除非我在主文件夹中安装它,任何想法为什么以及如何解决这个问题?

linux anaconda

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

makefile:运行目标时忽略依赖项

我的 Makefile 中有这个设置。

action1:
  does something

action2: action1
  does something else
Run Code Online (Sandbox Code Playgroud)

我想保留我的配置,以防我想action1用作 的依赖项action2,但有时我想在运行时忽略 action1 make action2(例如,我想运行make action2而不必包含action1)。我可以设置某种标志以在运行目标时忽略依赖项,我该怎么做?

makefile gnu-make

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

为什么Go中的地图最初会根据地图的大小而具有空值?

希望更好地理解地图。

给出以下代码:

package main

import "fmt"

type Vertex struct {
    Lat, Long float64
}

var m []map[string]Vertex
var m1 map[string]Vertex

func main() {
    m = make([]map[string]Vertex, 3)
    m1 = make(map[string]Vertex)
    m1["Bell Labs"] = Vertex{
        40.68433, -74.39967,
    }
    m = append(m, m1)
    fmt.Println(m)
    fmt.Println(len(m))
    fmt.Println(m[3]["Bell Labs"])
}
Run Code Online (Sandbox Code Playgroud)

我得到的输出

[map[] map[] map[] map[Bell Labs:{40.68433 -74.39967}]]
4
{40.68433 -74.39967}
Run Code Online (Sandbox Code Playgroud)

为什么数组中的前3个元素是空/空映射,为什么不打印出来[map[Bell Labs:{40.68433 -74.39967}]]呢?

go

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

使用 prisma graphql apollo 检查记录是否存在

尝试使用 Prisma 检查 Postgres 表中是否存在记录,但似乎我只能查询 id 字段,而不能查询任何其他字段,如namelocation,这会产生编译器错误

模型schema.prisma

model place {
  id             Int              @id @default(dbgenerated("nextval('place_id_seq'::regclass)"))
  name           String
  location       String @unique
}
Run Code Online (Sandbox Code Playgroud)

生成类型

export type Place = {
  __typename?: 'Place';
  name?: Maybe<Scalars['String']>;
  location?: Maybe<Scalars['String']>;

};
Run Code Online (Sandbox Code Playgroud)

查询解析器

let findPlace = await prisma.place.findUnique(
        {
          where: {
            name: "abc"
          }
        }
)
Run Code Online (Sandbox Code Playgroud)

错误

Type '{ name: string; }' is not assignable to type 'placeWhereUniqueInput'.
  Object literal may only specify known properties, and 'name' does not exist in type 'placeWhereUniqueInput'.ts(2322) …
Run Code Online (Sandbox Code Playgroud)

graphql apollo-server prisma

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