我无法获得更漂亮的扩展来使用我的配置文件。它继续使用全局设置(如 vscode 中的配置路径设置中所定义)。我做了一个示例项目:
https://github.com/Supperhero1/prettierTest
我在 .prettierrc 文件中将 tabWidth 设置为 1。当我运行“npx prettier --write”时。prettier 包正确地格式化了 test.ts 文档,使其缩进为 1,但是如果我保存文件(我打开了保存格式),它会被格式化回全局设置(4 个空格)。我删除了全局设置中的所有设置,但它默认为带有两个空格的选项卡。该扩展似乎完全忽略了配置文件。一位同事有这个扩展,它可以很好地处理配置文件。
我试图弄清楚什么可能会覆盖该设置,扩展描述表示确定设置的优先级是:
Prettier configuration file
.editorconfig
Visual Studio Code Settings (Ignored if any other configuration is present)
Run Code Online (Sandbox Code Playgroud)
在官方文档中,配置文件解析优先级是:
A "prettier" key in your package.json file.
A .prettierrc file written in JSON or YAML.
...
Run Code Online (Sandbox Code Playgroud)
看看我的 package.json 文件中没有 prettier 键,应该没有任何内容可以覆盖我的 .prettierrc 文件。我尝试重新启动 vscode 但没有帮助。有没有其他人遇到过这个问题,我不知道在哪里可以解决这个问题......
因此,我正在尝试制作一个响应式图像组件,该组件将根据屏幕分辨率/像素密度加载适当大小的图像。据我了解, srcset 属性正是为此而设计的,但我无法让它做我想做的事。我究竟做错了什么?这是渲染到 DOM 的元素:
<img src="/static/media/image2_1x.20b2e636.png" srcset="/static/media/image2_05x.198c1f0f.png 590w, /static/media/image2_1x.20b2e636.png 1180w, /static/media/image2_2x.632d77c5.png 2360w" sizes="(max-width: 1180px) 90vw, 1180px">
Run Code Online (Sandbox Code Playgroud)
我希望这个元素做的是,当屏幕尺寸大于 1180 像素时,它会为 1180 像素的宽度加载合适的图像。如果在高密度设备上显示,这里可能会加载2x图像(2360w),但通常会加载1x图像(1180w),当屏幕尺寸较小时,它应该计算90vw是多少px并根据像素密度和屏幕上 90vw 的像素数选择三个图像中最合适的一个。
实际发生的是该元素始终加载最大的图片(2360w 的图片)。即使我在我的 chrome 开发工具中打开响应模式并将屏幕宽度缩小到 300px 清除缓存并重新加载它仍然加载 2x 一个。
我尝试了多种尺寸属性。如果我将尺寸设置为 500 像素,它会将图像显示为 500 像素宽,但它仍会加载 2x 图像。
为什么会这样?我做错了吗?当图像宽度为 300 像素且不需要高分辨率版本时,如何使其加载 0.5 像素的图像?
我想要一个方法来告诉打字稿我的客户端已初始化(不再为空)。基本上,我能够做到这一点,但方式似乎不必要地冗长。这是我当前的实现:
export abstract class CacheService {
storeClient: ICacheStoreInterface | null = null
protected constructor(storeClientGetter: () => Promise<ICacheStoreInterface>) {
this.logger = Container.get(Logger)
void this.initialise(storeClientGetter)
}
private checkInitialisation(client: ICacheStoreInterface | null): asserts client is ICacheStoreInterface {
if (!this.storeClient) {
throw new Error('Attempting to access cache before initialisation')
}
}
private async initialise(storeClientGetter: () => Promise<ICacheStoreInterface>) {
try {
this.storeClient = await storeClientGetter()
} catch (error) {
this.logger.error(`Error initialising cache service:\n${error}`)
}
}
public async set(key: storeKey, value: any) {
this.checkInitialisation(this.storeClient)
await this.storeClient.set(key, …Run Code Online (Sandbox Code Playgroud) 我想要进行一个事务来保存新的表行以及该行的多对多辅助表条目。我使用相同的事务管理器保存这两个部分,但是当第二部分失败时,第一个部分不会恢复。为什么会发生这种情况?
await getManager().transaction(async transactionalEntityManager => {
newFeed = await transactionalEntityManager
.createQueryBuilder()
.insert()
.into(Feed)
.values({ ...feed })
.execute();
console.log('======================================\n', newFeed);
feed.sources.forEach(async source => {
console.log('==in forEach===\n', source.id, newFeed.identifiers[0].id);
await transactionalEntityManager
.createQueryBuilder()
.insert()
.into('feed_source')
.values({
sourceId: source.id,
feedId: newFeed.identifiers[0].id,
fontColor: feed.fontColor ? feed.fontColor : null,
postColor: feed.postColor ? feed.postColor : null
})
.execute();
});
});
Run Code Online (Sandbox Code Playgroud)
和语法有关系吗?我以前没有使用过插入查询生成器语法。.execute() 是否会忽略该事务?这样做的正确方法是什么?