这个问题存在争议,也没有一致性,所以我想澄清一下打字稿的类、文件名、后缀等的命名标准。我想知道,你在 Typescript 项目中如何命名抽象类、接口以及逻辑组织代码?
可能的解决方案:
对于接口:
对于抽象类:
使用 C# 的示例
public class User : AbstractUser, IUser
Run Code Online (Sandbox Code Playgroud)
Java 和 PHP 中相同
public class User extends AbstractUser implements UserInterface
Run Code Online (Sandbox Code Playgroud)
在打字稿中
export class User extends AbstractUser implements UserInterface
Run Code Online (Sandbox Code Playgroud)
这是基于 C#、Java 和现代 PHP7+ 等语言的框架中使用的常规方法
微软建议添加“Interface”作为后缀,这对我来说是正确的。 https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Interfaces.md#class-types
另一个流行的风格指南建议不要为接口的前缀添加任何后缀,对我来说违反了规则,可读性和整体看起来都是错误的。https://basarat.gitbooks.io/typescript/content/docs/styleguide/styleguide.html#interface
export class User extends AbstractUser implements User
Run Code Online (Sandbox Code Playgroud) 为节点转换Typescript的最佳(实时?)方法是什么?
我正在使用WebStorm并在后台运行gulp任务backend:watch来监听更改.因此,当我在WebStorm中点击"保存"时,它确实将TS转换为JS并存储在/build目录下.
我的方法效果很好,但是转换是耗时的 - 每次运行需要两到三秒,秒会变成分钟,依此类推.
有没有办法优化它,一个更好的选择?
//////////////////////////////////////////////
// Backend tasks
//////////////////////////////////////////////
const appSourceDir = path.join(dir, '/app');
const appSourceGlob = `${appSourceDir}/**/*.*`;
const appSourceRelativeGlob = 'app/**/*.*';
const appCodeGlob = `${appSourceDir}/**/*.ts`;
const appCodeRelativeGlob = 'app/**/*.ts';
const appFilesGlob = [appSourceGlob, `!${appCodeGlob}`];
const appFilesRelativeGlob = [appSourceRelativeGlob, `!${appCodeRelativeGlob}`];
const appBuildDir = path.join(dir, '/build');
gulp.task('backend:symlink', [], function (done) {
const appTargetDir = path.join(dir, '/node_modules/app');
// symlink for app
fs.exists(appTargetDir, function (err) {
if (!err) {
fs.symlinkSync(appBuildDir, appTargetDir, 'dir'); …Run Code Online (Sandbox Code Playgroud)