可能是一个奇怪的问题,但我很好奇是否可以创建一个需要一个属性或另一个属性的接口.
所以,例如......
interface Message {
text: string;
attachment: Attachment;
timestamp?: number;
// ...etc
}
interface Attachment {...}
Run Code Online (Sandbox Code Playgroud)
在上面的例子中,我想确定是存在text还是attachment存在.
希望这是有道理的.
提前致谢!
编辑:这就是我现在正在做的事情.认为它有点冗长(输入botkit for slack).
interface Message {
type?: string;
channel?: string;
user?: string;
text?: string;
attachments?: Slack.Attachment[];
ts?: string;
team?: string;
event?: string;
match?: [string, {index: number}, {input: string}];
}
interface AttachmentMessageNoContext extends Message {
channel: string;
attachments: Slack.Attachment[];
}
interface TextMessageNoContext extends Message {
channel: string;
text: string;
}
Run Code Online (Sandbox Code Playgroud) 考虑其中一个对象可以有准确的FooBar或Baz界面如下.
interface FooBar {
foo: string;
bar: string;
}
interface Baz {
baz: string;
}
Run Code Online (Sandbox Code Playgroud)
我的理解是,可以通过在FooBar和之间创建联合来处理这种"一种或另一种"情况Baz.
type FooBarOrBaz = FooBar | Baz;
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好...
我遇到的问题是以下对象传递类型检查:
const x: FooBarOrBaz = {
foo: 'foo',
baz: 'foo',
};
Run Code Online (Sandbox Code Playgroud)
这是一个错误吗?
提前致谢!
正如标题所述,我很好奇如果无法在特定页面上找到属性,那么包中的html_text()函数是否可以rvest存储NA值.
我目前正在运行超过199页(其工作正常;已经在一些变量上测试).
目前,当我搜索仅存在于199页中的某些(136)中的值时,html_text()仅返回136个字符串的向量.这没用,因为没有NAs我无法确定哪些页面包含有问题的变量.
我看到它html_atts()能够接收default输入,但不能html_text().有小费吗?
非常感谢!