我刚刚开始使用 Typescript 来使用 Fastify,并且非常喜欢它。
但是,我试图弄清楚是否可以输入响应负载。我有用于序列化工作的响应模式,这可能就足够了,但我有内部类型化的对象(例如 IUser),最好让 Typescript 检查。
以下内容效果很好,但我想返回一个 TUser 例如,如果我返回不同的内容,则有打字稿。使用模式仅仅排除字段。
interface IUser {
firstname: string,
lastname: string
} // Not in use in example
interface IUserRequest extends RequestGenericInterface {
Params: { username: string };
}
const getUserHandler = async (
req: FastifyRequest<IUserRequest, RawServerBase, IncomingMessage | Http2ServerRequest>
) => {
const { username } = req.params;
return { ... }; // Would like to return instance of IUser
};
app.get<IUserRequest>('/:username', { schema }, getUserHandler);
Run Code Online (Sandbox Code Playgroud)
我可以为响应扩展一个等效的 RequestGenericInterface 吗?
小更新:似乎可以使用 …
我将 Github Actions 工作流用于 Node 和 PHP 项目的 CI/CD 流程。
在工作流中,我将我的存储库克隆到 Github Actions 运行器虚拟机中。然后为了在工作流中运行测试,我必须将.env文件放在克隆的存储库中。
问题是我的.env文件不是存储库的一部分(这是普遍存在的做法)。
为了解决这个问题,我使用了我认为的一种解决方法:设置MY_PROJECT_ENVGithub Action sercret 变量,手动将我的.env文件内容放在那里,然后.env使用 Linux 控制台在我的工作流中动态创建文件echo "${{ secrets.MY_PROJECT_ENV}}" > .env。这有效。
但我想知道是否有其他方法可以向.envGithub Actions 工作流提供文件?
php continuous-integration environment-variables node.js github-actions
我需要将所有 3 个元素组合在一个容器中的图像。但是,无论我在 Docker Hub 上使用 Google 搜索还是搜索,我都没有发现要保存的图像PHP,Apache并且MySQL在同一个容器/Dockerfile 中。
有人可以建议创建所需容器的方法吗?
我也很感谢解释为什么这种图像/容器不可用的原因?
作为旁注,我自己无法想象MySQL在不同的容器中分离服务器是可行的,因为它DB本身没有与容器一起保存并且其中只有MySQL服务器。因此,即使MySQL在同一个容器中,仍然与DB自身完全解耦。
假设你有一个对象类型:
type Person = {
name?: string;
color?: string;
address?: string;
}
Run Code Online (Sandbox Code Playgroud)
但是,您想将该类型更改为以下类型,您知道名称和颜色将存在。
type Person = {
name: string;
color: string;
address?: string;
}
Run Code Online (Sandbox Code Playgroud)
因此,有这样的函数
const throwIfUndefined = (
object: {[key: string]: any},
requiredKeys: string[]
): ReturnTypeHere => {
for (const key of requiredKeys) {
if (!object[key]) throw new Error("missing required key");
}
return object;
};
Run Code Online (Sandbox Code Playgroud)
输入函数参数以及返回类型 ( ReturnTypeHere) 的正确方法是什么?如果写得正确,下面的代码将 1) 抛出错误 2) 控制台记录名称。它永远不会控制台日志未定义。
const person = {...}
const requiredKeys = ["name", "color"];
const verifiedPerson = throwIfUndefined(person, requiredKeys);
console.log(verifiedPerson.name)
Run Code Online (Sandbox Code Playgroud) 我一直在尝试解决我遇到的这个错误。据我所知,这是空合并运算符(??)的问题。我在网上关注了各种文档,但遇到了同样的问题。关于如何更新我的构建器以避免出现此问题有什么想法吗?
https://babeljs.io/docs/en/babel-plugin-syntax-nullish-coalescing-operator
错误
Uncaught Error: Module parse failed: Unexpected token (129:61)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| const transformOuterRef = React.useRef(null);
| const transformInnerRef = React.useRef(null);
> const target = (portal == null ? void 0 : portal.current) ?? gl.domElement.parentNode;
| React.useEffect(() => {
| if (group.current) {
at eval (webpack:///./node_modules/@react-three/drei/web/Html.js?:1)
at Object../node_modules/@react-three/drei/web/Html.js (bundle.js:2069)
at __webpack_require__ (bundle.js:793)
at fn (bundle.js:101)
at eval (webpack:///./node_modules/@react-three/drei/index.js?:2) …Run Code Online (Sandbox Code Playgroud) node.js ×2
php ×2
typescript ×2
architecture ×1
docker ×1
fastify ×1
javascript ×1
mysql ×1
webpack ×1