我知道python是动态类型的语言,但是我想知道这是否可能,让我说我有一个名为people的类的列表。
people = []
people.append(Person('james'))
for p in people :
p.name = p.name + '_'
是否有方法指定p的类型,如下所示:
for p:Person in people :
p.name = p.name + '_'
我要求这样做的原因是,IDE似乎将p视为类型any/object,而intellisense在我输入p.时没有识别任何属性--我使用
我有一个使用Visual作为IDE的Range6应用程序,我安装并导入了我创建的JavaScript库,以便在我的installed中使用它。我的JS库有函数和类,所有这些都带有标准的JavaScript注释,例如:
/**
* Send a custom greeting to a person.
* @param {string} name - Name of person to greet
* @return {string} Return a custom greeting
*/
export function greetings(name) {
return
考虑以下代码:
class BaseType {
private _group: any = {};
private _a: number;
constructor() { }
group(g?: any): this | any {
if (!g) {
return this._group;
}
this._group = g;
return this;
}
another(a?: number): this | number {
if
我尝试过许多扩展/配置,但无法让vscode检测变量何时未定义。例如,像这样简单的内容没有显示警报:
# b and c are not defined anywhere
a = b + c
我希望看到linter或其他扩展提醒我没有声明b和c。相反,我根本没有看到任何突出显示或通知。
我已经安装了以下扩展: Ruby,日光图,红宝石,robocop,VSCode Ruby.我还为linter、日光图和intellisense添加了一些自定义的信息:
"ruby.linter.run": "onSave",
"solargraph.definition
我最近发现,您可以为javascript项目在VSCode中实现VSCode泛型,这是非常棒的。我在过去写JS时遇到的一个大问题是让intellisense永远不知道我处理的是哪种类型。
我遵循了关于如何实现泛型(使用@template注释)的文档:
它的工作原理主要是因为我可以正确地看到我的类类型。问题是,它似乎并不知道任何非静态方法和属性。
下面是一些示例代码:
"use strict";
class Parent {
age = 10;
outputAge() {
console.log(`My age is ${this.age}`)
虽然我对字典的结构使用类型暗示,但VSCode的微软intellisense引擎似乎无法识别字典中的类。
例如,这不起作用:
class MyClass():
def myf(self, methods):
foo = "bar"
return foo
mystring: str
mydict: Dict[str: MyClass] = {}
# mydict[mystring]. # <--- after typing the point ".", I expected hints from inte
我没有在我的react项目中启用类型记录,我只是将可选的链导入到我的项目中,它可以工作,但是vscode仍然会给我带来语法错误。我检查了我所有的扩展,没有tslint。因此,我不知道错误来自何处,以及如何禁用此语法检查?
最新情况:
VS Code 1.41 supports optional chaining in both JavaScript and TypeScript files. This support includes syntax highlighting and IntelliSense.
这解决了我的problem.just升级vscode到最新版本的问题。