我使用插件配置了vlode的ESlint,现在我想知道是否有某种方法可以阻止ESlint向我显示解析器/语法错误,因此我可以反而查看Salsa语言服务默认提供的语法错误.
我的问题很奇怪(我想).
使用AppCompat我对?attr/colorPrimary的引用不起作用.
colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">@color/primary_material_dark</color>
<color name="colorPrimaryDark">@color/primary_dark_material_dark</color>
<color name="test">#ff2800</color>
</resources>
Run Code Online (Sandbox Code Playgroud)
styles.xml:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:colorPrimary">@color/primary_material_dark</item>
<item name="android:colorPrimaryDark">@color/primary_dark_material_dark</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
activity_main.xml中:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity"
android:background="?attr/colorPrimary">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="@color/colorPrimary"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
/>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="COLORCLOR"
android:background="?attr/colorPrimary"/>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
看到它的样子:
但是当我用实际的颜色参考替换?attr/colorPrimary引用时,一切似乎都能正常工作.真的很困惑这个,尝试从工具栏中删除主题和popupTheme属性,仍然无法正常工作.
PS.?attr/colorPrimaryDark工作得很好
我可以创建一个 typeguard,它断言对象中存在特定属性(或具有特定类型)。
IE
我有一个界面Foo:
interface Foo {
bar: string;
baz: number;
buzz?: string;
}
Run Code Online (Sandbox Code Playgroud)
现在一个类型的对象Foo将有一个可选的属性 buzz。我将如何编写一个断言存在 buzz 的函数:即
const item: Foo = getFooFromSomewhere();
if (!hasBuzz(item)) return;
const str: string = item.buzz;
Run Code Online (Sandbox Code Playgroud)
我将如何实施hasBuzz()?类似于打字机的东西:
function hasBuzz(item: Foo): item.buzz is string {
return typeof item.buzz === 'string'
}
Run Code Online (Sandbox Code Playgroud)
这样的东西存在吗?
PS:我知道我可以这样做:
const item = getFooFromSomewhere();
if (typeof item.buzz === 'string') return;
const str: string = item.buzz;
Run Code Online (Sandbox Code Playgroud)
但是我的实际用例要求我有一个单独的函数来断言buzz.
我正在为Vue.js构建一个插件组件.使用带有vue-loader等的标准webpack配置
在一个简单的库中,我将我希望在我dependencies的package.json中"需要"的模块放入.但是,由于Webpack将我的所有代码和依赖项编译成一个包,我不知道在哪里放置依赖项:axios.
希望有人对此有所了解.
所以我有一个名为 和 的基本模式Base,使用Base.discriminator(...)我创建了名为ChildA和的子类型ChildB。
如果我这样做,Base.find({})我将获得所有文档,是否可以将实例转换为BasetoChildA或ChildB取决于鉴别器值?
我有以下通用功能:
export function useClientRequest<T, R extends (...args: any) => AxiosPromise<T>>(
func: R,
...args: Parameters<R>
): [T | undefined, boolean, AxiosError | undefined] {
// Irrelevant
}
Run Code Online (Sandbox Code Playgroud)
总而言之,函数的返回值包含一个类型为 T 的值,应该按照上面的描述进行推断。
然后我尝试按如下方式使用它:
interface Foo {
// ...
}
function fooGetter(url: string): AxiosPromise<Foo> {
return Axios.get<Foo>(url);
}
const [data] = useClientRequest(fooGetter, 'url.com');
Run Code Online (Sandbox Code Playgroud)
但是,我的 IDE 报告该data类型为unknown,因为T被推断为unknown.
我做错了什么还是这是 TypeScript 的限制?
打字稿 v3.7.2
我知道我可以指定类型参数。我想知道为什么它们被错误地推断出来,以及我是否可以以某种方式更改实现以帮助推断机制。
这是一个基本用例:使用 null 初始化变量,然后更改某些嵌套循环/函数中的值:
let a: number | null = null;
[1].forEach(() => {
a = 1;
});
if (a != null)
a.toFixed(); // Error: Property 'toFixed' does not exist on type 'never'.
Run Code Online (Sandbox Code Playgroud)
但是 typescript 推断a的类型是never。我会假设没有if它会假设它null | number在这种情况下我会得到一个错误,指出该属性不存在于 null,但为什么它假设它永远不会仅基于初始分配值。
难道我做错了什么?
我们有几个使用 Quasar 构建的 SPA。一切都很好,但现在我们看到某些组件可以提取到共享组件中。
计划是提取相关代码并发布到我们的私有 npm 存储库。如何构建并发布使用 Quasar 中的组件构建的组件?
使用 vuetify 之类的东西,我可以只导入所需的组件并开始构建我的组件,但在 Quasar 的情况下,导入是根据配置的主题来解决的。
我正在使用 Vuetify 并希望v-navigation-drawer和v-toolbar固定到视口但v-footer不是,即只有在滚动到页面底部时才会出现的场景。
我已将fixed道具应用于抽屉和工具栏,它们很好地粘在视口上。我还将absolute道具添加到页脚,使其出现在页面的最底部。
然而,即使页脚不在视图中,抽屉在末端留下了“固定”页脚会占用的空间,这看起来不正确。
我该如何解决这个问题?
From我正在尝试创建一个错误类型,并为 any 提供一揽子实现Error,但是由于该类型本身就是一个错误类型,所以Error我遇到了冲突:
pub struct ApiError(pub i64, pub String);
impl<T: Error> From<T> for ApiError {
fn from(err: T) -> Self {
Self(500, err.to_string())
}
}
impl Error for ApiError {}
Run Code Online (Sandbox Code Playgroud)
error[E0119]: conflicting implementations of trait `std::convert::From<ApiError>` for type `ApiError`
--> src/lib.rs:5:1
|
5 | impl<T: Error> From<T> for ApiError {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `core`:
- impl<T> From<T> for T;
Run Code Online (Sandbox Code Playgroud)
我认为这是因为我通过实施创建的Error循环ApiError。是否可以这样说T: Error & not ApiError …
node.js ×3
typescript ×3
vue.js ×3
javascript ×2
android ×1
eslint ×1
mongoose ×1
npm ×1
package.json ×1
rust ×1
traits ×1
typeguards ×1
vuetify.js ×1
webpack ×1