在许多情况下,通过专用包或与 npm 包本身一起提供的第三方类型定义@types/*后来被发现不完整或与新的依赖项不兼容。
因此,我正在寻找一种直接的方法来覆盖node_modules. 理想情况下,我只需将它们复制粘贴到我的存储库中,并告诉 TypeScript 编译器使用我的类型即可。
我找到了 3 种可能的解决方案,但没有一个特别好:
declare module 'printer' {
export function print(msg: string): void;
}
declare module 'printer/color' {
export function print(msg: string, color: string): void;
}
// WARNING: If you `import` or `export` anything here,
// this will suddenly *augment*, not *override* the
// 'printer' module.
Run Code Online (Sandbox Code Playgroud)
node_modules因为
declare module 'printer' {}import print from 'printer/color')必须显式声明为单独的模块声明。import/ export …John Resig建议使用setInterval()以减少调用处理程序的次数 - 请参阅http://ejohn.org/blog/learning-from-twitter/
约翰的博客文章解决方案:
var outerPane = $details.find(".details-pane-outer"),
didScroll = false;
$(window).scroll(function() {
didScroll = true;
});
setInterval(function() {
if ( didScroll ) {
didScroll = false;
// Check your page position and then
// Load in more results
}
}, 250);
Run Code Online (Sandbox Code Playgroud)
可以调用一个持续间隔真的是一个明智的想法吗?
迈克尔杰克逊的方法是否更有意义,因为它并不意味着我们不断进行民意调查?
迈克尔的评论解决方案:
var timer = 0;
$(window).scroll(function () {
if (timer) {
clearTimeout(timer);
}
// Use a buffer so we don't call myCallback too often.
timer = setTimeout(myCallback, 100);
});
Run Code Online (Sandbox Code Playgroud)
任何人都可以分享任何意见/建议吗?
丰富
我今天在生产中有以下 graphql 模式定义:
type BasketPrice {
amount: Int!
currency: String!
}
type BasketItem {
id: ID!
price: BasketPrice!
}
type Basket {
id: ID!
items: [BasketItem!]!
total: BasketPrice!
}
type Query {
basket(id: String!): Basket!
}
Run Code Online (Sandbox Code Playgroud)
我想重命名BasketPrice为 just Price,但是这样做会对架构造成重大更改,因为客户端可能会在片段中引用它,例如
fragment Price on BasketPrice {
amount
currency
}
query Basket {
basket(id: "123") {
items {
price {
...Price
}
}
total {
...Price
}
}
}
Run Code Online (Sandbox Code Playgroud)
我曾希望可以为向后兼容起别名,例如
type Price {
amount: Int!
currency: String!
}
# Remove …Run Code Online (Sandbox Code Playgroud)