小编use*_*366的帖子

solana web3 verifyTransaction @deprecated 使用 TransactionConfirmationConfig 示例

使用此代码 VS 显示不推荐使用的警告:

\n
\n

(方法)Connection.confirmTransaction(策略:字符串,承诺?:\nCommitment):Promise<RpcResponseAndContext>(+1\noverload)@deprecated \xe2\x80\x94 相反,使用\nTransactionConfirmationConfig 调用confirmTransaction

\n

已弃用签名 '(strategy: string, Commitment?: Commitment):\nPromise<RpcResponseAndContext>' of\n'connection.confirmTransaction'

\n
\n
const airDropSol = async () => {\n  try {\n    const connection = new Connection(clusterApiUrl("devnet"), "confirmed");\n    const airdropSignature = await connection.requestAirdrop(\n      publicKey,\n      2 * LAMPORTS_PER_SOL\n    );\n    await connection.confirmTransaction(airdropSignature);\n  } catch (error) {\n    console.error(error);\n  }\n};\n
Run Code Online (Sandbox Code Playgroud)\n

谁能给我一个新语法的例子吗?

\n

typescript solana solana-web3js

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

zustand typescript 持久化如何输入 store

我有一家简单的商店

interface CartState {
  cart: { [id: string]: CartDto };
  addItem: ({ id, image, name, price }: Omit<CartDto, "quantity">) => void;
  removeItem: (id: string) => void;
  reset: () => void;
}
export const useCart = create<CartState>((set, get) => ({
  cart: {},
  addItem: ({ id, image, name, price }) => {
    set(() => {
      const cart = get().cart;
      if (!cart[id]) {
        cart[id] = {
          id,
          image,
          name,
          price,
          quantity: 0
        };
      }

      cart[id].quantity += 1;

      return { cart };
    });
  }, …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs react-state

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

Angular Ivy strictTemplates true 类型 'boolean | null' 不可分配给类型 'boolean'

我已将我的应用程序更新到 9 版本。一切都很好,但我在将 strictTemplates 设置为 true 时遇到了问题。例如这段代码

loaded$: Observable<boolean>
[loaded]="loaded$ | async"
@Input() loaded!: boolean;
Run Code Online (Sandbox Code Playgroud)

我有错误类型 'boolean | null' 不能分配给类型 'boolean'。

这修复了错误

@Input() loaded!: boolean | null;
Run Code Online (Sandbox Code Playgroud)

但是我看不到有人acn解释我的意思,好吗?

angular angular-ivy

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

React 查询突变打字稿

我只是在玩反应查询

带打字稿

我的意思是我做了我的第一次尝试

这是正确的方法吗?

const useCreateTodo = () => {
  const queryClient = useQueryClient();
  return useMutation(
    (todo: TodoDto) => axios.post(`${URL}/todos`, todo).then((res) => res.data),
    {
      onMutate: async (newTodo: TodoDto) => {
        // Cancel any outgoing refetches (so they don't overwrite our optimistic update)
        await queryClient.cancelQueries("todos");

        // Snapshot the previous value
        const previousTodos = queryClient.getQueryData("todos");

        // Optimistically update to the new value
        queryClient.setQueryData<TodoDto[] | undefined>("todos", (old) =>
          old ? [...old, newTodo] : old
        );

        // Return a context object with the snapshotted …
Run Code Online (Sandbox Code Playgroud)

reactjs react-query

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

提供Angular服务的VS forRoot

我想知道这些代码是否正确

是等价与否.

我可以使用provideIn吗?

与...相同的结果

forRoot?

提前致谢

@Injectable({
  providedIn: 'root'
})
export class MyService {
  constructor() { }
}
Run Code Online (Sandbox Code Playgroud)

[我仍然会将myModule保留为与allowedId单例服务一起使用]

angular

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

React typescript如何使用useRef作为prop

我只是在玩打字稿,但在自定义元素中使用 useRef 时遇到问题

将其作为 prop 传递

我尝试过

import React from "react";

export interface InputProps
  extends React.InputHTMLAttributes<HTMLInputElement> {
    ref: HTMLElement | null
  }

const Input: React.FC<InputProps> = ({ ...inputProps }) => {
  return (
    <input
      className="px-2 py-1 text-gray-700 text-2xl bg-white border-2 border-gray-200 hover:border-purple-300 focus:outline-none focus:bg-white rounded-l-lg shadow-md"
      {...inputProps}
    />
  );
};
export default Input;


import React, { useRef } from "react";

import Input from "./input";
import Button from "./button";

const Form: React.FC = () => {
  const todoRef = useRef<HTMLElement | …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs

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

角度服务单元测试 DoneFn

我正在关注 angular 官方文档,我可以看到以下代码:

it("#getObservableValue should return value from observable", (done: DoneFn) => {
    service.getObservableValue().subscribe(value => {
      expect(value).toBe("observable value");
      done();
    });
  });
Run Code Online (Sandbox Code Playgroud)

我想知道 DoneFn 来自哪里,因为我在输入时没有错误。

unit-testing angular

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

Ngrx如何测试后卫

我想测试一下这个简单的后卫canActivate和canLoad如何管理它?我做了第一步管理注入的商店

@Injectable({
  providedIn: 'root'
})
export class AuthGuard implements CanActivate, CanLoad {
    constructor(private store: Store<AuthState>) {}

    canActivate(): Observable<boolean> {
        return this.store.pipe(
            select(selectIsAuthenticated),
            map(isValidToken => {
                if (!isValidToken) {
                    this.store.dispatch(new Logout());
                    return false;
                }
                return true;
            }),
         take(1)
       );
    }

    canLoad(): Observable<boolean> {
        return this.store.pipe(
            select(selectIsAuthenticated),
            map(isValidToken => {
                if (!isValidToken) {
                    this.store.dispatch(new Logout());
                    return false;
                }
                return true;
            }),
            take(1)
        );
    }
}
Run Code Online (Sandbox Code Playgroud)

我的第一步

export const authReducer: ActionReducerMap<{}> = {
  status: {}
};
describe('AuthGuard', () => {
  let store: Store<{}>; …
Run Code Online (Sandbox Code Playgroud)

ngrx angular

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

带有 ChangeDetectionStrategy.OnPush 的 Angular 单元测试不起作用

我有这个简单的组件。

@Component({
  changeDetection: ChangeDetectionStrategy.OnPush,
  selector: 'app-spinner',
  template: `
    <ng-container *ngIf="loading; else valueTpl">
      <strong>loading....</strong>
    </ng-container>
    <ng-template #valueTpl>
      <span>{{ value }}</span>
    </ng-template>
  `
})
export class SpinnerComponent {
  @Input() loading = false;
  @Input() value!: string;
}
Run Code Online (Sandbox Code Playgroud)

在运行中它运行良好,但是当我去测试时测试失败

it('should show spinner when loading true', () => {
    component.loading = true;
    fixture.detectChanges();
    const strong = debugElement.query(By.css('strong'));
    const el: HTMLElement = strong.nativeElement;
    expect(el).not.toBeNull();
  });
Run Code Online (Sandbox Code Playgroud)

使用 ChangeDetectionStrategy.OnPush 测试组件的正确方法是什么?

更新

等待更好的解决方案,我解决了它:

beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [SpinnerComponent]
    })
      .overrideComponent(SpinnerComponent, {
        set: { changeDetection: ChangeDetectionStrategy.Default }
      })
      .compileComponents(); …
Run Code Online (Sandbox Code Playgroud)

unit-testing angular

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

React Native expo debugger-ui 错误:EISDIR:对目录进行非法操作,读取

我使用 expo 启动了一个新应用程序,但是当我尝试使用 cmd-d 打开 debugger-ui 并单击 debug remote js 时,我收到了这条丑陋的消息:

Error: EISDIR: illegal operation on a directory, read
    at Object.readSync (node:fs:720:3)
    at tryReadSync (node:fs:430:20)
    at Object.readFileSync (node:fs:476:19)
    at UnableToResolveError.buildCodeFrameMessage (/Users/me/my/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:304:17)
    at new UnableToResolveError (/Users/me/my/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:290:35)
    at ModuleResolver.resolveDependency (/Users/me/my/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:168:15)
    at DependencyGraph.resolveDependency (/Users/me/my/node_modules/metro/src/node-haste/DependencyGraph.js:353:43)
    at /Users/me/my/node_modules/metro/src/lib/transformHelpers.js:271:42
    at Server.<anonymous> (/Users/me/my/node_modules/metro/src/Server.js:842:41)
    at Generator.next (<anonymous>)
Run Code Online (Sandbox Code Playgroud)

我尝试谷歌搜索,但没有一个解决方案有效 有想法解决它吗?

react-native expo

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