小编Tom*_*Tom的帖子

在 Typescript 中,有没有办法限制/限制导出的函数,使其只能由某些文件导入?

我希望开发人员使用类/接口而不是直接导入函数。

有没有办法限制只有类才能导入该函数?

我不想将所有功能放在一个文件中,因为它在大型项目中不可扩展

即我不想使用这种模式:

// myclass.ts

// no exports on the functions
function foo(){ ... }
function bar(){ ... }

export class MyClass {
 Foo(){ return foo() }
 Bar(){ return bar() }
}

Run Code Online (Sandbox Code Playgroud)

我想要实现的目标:

// foo.ts
export function foo(){ ... } 
// I want this to be private but it needs to be exported so the class below can use it

// bar.ts
export function bar() { ... }

// myclass.ts
import { foo } from 'foo';
import { bar …
Run Code Online (Sandbox Code Playgroud)

import export private function typescript

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

如何在类和派生类之间使用接口?

我目前正在尝试制作国际象棋游戏,并试图实现一个界面,但我无法访问界面.

public interface IChessPiece
{
     bool CheckMove(int row, int col);
}

public class ChessPiece { ... }

public class Pawn : ChessPiece, IChessPiece
{
     public bool CheckMove(int row, int col) { ... }
}

public class ChessPieces {  public List<ChessPieces> chessPieces; ... }
Run Code Online (Sandbox Code Playgroud)

我似乎无法访问CheckMove()方法.

board.chessPieces.Find(x => <condition>).CheckMove(row, col);
Run Code Online (Sandbox Code Playgroud)

c# interface class

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

标签 统计

c# ×1

class ×1

export ×1

function ×1

import ×1

interface ×1

private ×1

typescript ×1