我正在尝试在 vs code 中调试打字稿。据我研究,您需要在 vs code 的 launch.config 中设置 outfiles 属性,以映射您在已编译的 .js 文件中在 TypeScript 文件中设置的断点,如此处指定。
当我尝试设置我的时,出现以下错误:
我在谷歌中没有发现任何关于此错误的信息,因为打字稿调试器需要此设置才能工作,正如VS Code 文档中所示。
预先感谢您的任何帮助。
编辑:
启动.json:
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}",
"preLaunchTask": "tsc",
"sourceMaps": true
}
]
Run Code Online (Sandbox Code Playgroud)
ts配置:
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es5", /* Specify ECMAScript target version: 'ES3' …
Run Code Online (Sandbox Code Playgroud) 我跟随在一个更大的班级中解释我的问题,并使用一个更小的易于遵循的确切示例。我得到了一个很大的类,有很多不同类型的属性,获取和设置它们各自的类变量。
public class Foo() {
int property1 { get => _property1 ; set => _property1 = value;}
string property2 { get => _property2 ; set => _property2 = value;}
Vector3 property3 { get => _property3 ; set => _property3 = value;}
bool property4 { get => _property3 ; set => _property4 = value;}
}
Run Code Online (Sandbox Code Playgroud)
我在示例中放置了 4 个属性,但在实际示例中却有很多。我需要在所有属性的集合中应用一个逻辑,这取决于 property4 布尔值,所以我没有在我的属性的所有 setter 中编写相同的代码,而是尝试创建一个在所有属性中都可以调用的通用方法。
所以,我做了一个枚举:
public enum properties {
property1,
property2,
property3,
property4
}
Run Code Online (Sandbox Code Playgroud)
这样我就可以使用涉及反射的方法设置我的属性,将属性类型作为参数:
public void setLogic<T>(properties property, T value) {
//irrelevant …
Run Code Online (Sandbox Code Playgroud) 我正在做的总体思路是从用户窗体接收用户输入,将该数据添加到单行,然后我想在该原始行正下方复制该行“x”次。这种情况下的“x”行数也由用户输入的值决定。
例如,假设用户填写 UserForm 并且他们选择的“x”是 5。我的 VBA 代码将获取他们输入的信息,将其放在第 2 行,然后基本上复制/粘贴该行到接下来的 4 行排下来。然后最终结果看起来像这样(除了 C 列中的每个单元格都将是“44”,我不确定为什么该列决定增加 1,但这是我需要帮助修复的另一件事):
我假设我可以编写 VBA 代码来复制和粘贴行 'x' 次数,但我认为自动填充会更容易,因为每一行的值都相同。我只是不知道如何指定一个范围,该范围将根据用户输入的内容而变化。这是我为特定范围自动填充的代码,我不确定如何将其更改为不同的范围
numOfLines = (LastL - FirstL) + 1 'don't worry about how I get this, it's a number that I know is correct
With Sheets("QuoteCSV")
Sheets("QuoteCSV").Select
' Get the current row
Dim curRow As Long
If .Range("B1") = "" Then
curRow = 1
Else
curRow = .Range("B" & .Rows.Count).End(xlUp).Row + 1
End If
' Add items to the first row (row 2) …
Run Code Online (Sandbox Code Playgroud) 我终于让打字稿在我的项目中工作了,但是断点不会停在正确的行上,并且变量值不可用,直到您在逐步执行中进入更多行代码。如果源映射中不匹配,则似乎存在某些 ttype。我尝试按照此处的说明将 SourceMapDevToolPlugin 添加到 webpack 配置文件中来解决此问题。但并不能解决问题。
下面的截图说明了我的意思:
myString 未定义,尽管该行应该已被执行。
之后它直接跳转到函数(而不是const myNumber = myFunc(5);
调用函数的地方)并且字符串的值可用,所以这很奇怪。
下面是我的 webpack 配置、launch.json 和 tsconfig。
网络包配置:
const webpack = require('webpack');
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
// const SourceMapDevToolPlugin = require('');
const modulesPath = path.resolve(__dirname, 'node_modules');
const srcPath = path.resolve(__dirname, 'src');
const outputPath = path.resolve(__dirname, 'dist');
const basename = process.env.BASENAME || '/';
const mode = process.env.NODE_ENV === 'production' ? 'production' : 'development';
module.exports = {
mode,
devtool: …
Run Code Online (Sandbox Code Playgroud) 考虑以下代码段,您可以在其中从MyType
实例参数获取浮点数(或相应类型):
void myMethod(MyType floatArgument) {
float myFloat = (float)MyType.Value;
if (myFloat < 100) {
//not meaningfull code
}
}
Run Code Online (Sandbox Code Playgroud)
如果在侦听器中不断调用该方法,或者在物理或图形引擎的更新中不断调用该方法,那么将其设为这样的类变量是否在效率方面会更好?:
private float myFloat
void myMethod(MyType floatArgument) {
myFloat = (float)MyType.Value;
if (myFloat < 100) {
//not meaningfull code
}
}
Run Code Online (Sandbox Code Playgroud)
该变量仅在本地范围内使用,因此每次都会在堆栈中创建 AFAIK。所以从它创建一个类变量会更快,这样即使该变量的内存也会在堆上并且内存消耗会更高,代码会运行得更快。
我知道对于一个浮点数来说可能没什么大不了的,但是把它当作是很多变量或一个大数据类的实例。
这个推理正确吗?
我正在使用 node.js 运行此代码:
const tasksSorted = {};
tasksSorted[0] ??= {};
Run Code Online (Sandbox Code Playgroud)
我相信这是有效的。我收到错误:
tasksSorted[0] ??= {};
^^^
SyntaxError: Unexpected token '??='
Run Code Online (Sandbox Code Playgroud)
在浏览器中我可以使用??=
逻辑无效赋值
Unity的线条渲染器组件有一个要附加的材质,以便线条渲染器使用它来相应地在场景中显示线条渲染器:
问题是,如果您更改此材质颜色,它会起作用,并且在运行时也可以在编辑器本身中更改它。但阿尔法却并非如此。它在编辑和代码中都不响应。我试过:
Color targetColor = new Color(0,0,0,a);
_unityEngineLineRender.sharedMaterial.SetColor("Color", targetColor);
Run Code Online (Sandbox Code Playgroud)
和:
Color targetColor = new Color(0,0,0,a);
_unityEngineLineRender.sharedMaterial.color = targetColor;
Run Code Online (Sandbox Code Playgroud)
但它不起作用。这么简单的事情能做到吗?如果是这样,怎么办?
提前致谢
我有这个代码:
private int _someProperty;
public int SomeProperty
{
get => _someProperty;
set => SetProperty(ref _someProperty, value);
}
private void SetProperty<T>(ref T field, T value)
{
if (!field.Equals(value))
{
field = value;
}
}
Run Code Online (Sandbox Code Playgroud)
我需要它是SetProperty<T>
因为我需要在一个具有大量属性的大类中设置逻辑,并且该逻辑适用于所有属性。_someProperty
该代码适用于变量的情况。但就我而言,它不起作用,因为我引用了嵌套类的另一个属性,因此我收到编译错误:“属性或索引器可能无法作为 out 或 ref 参数传递”。
由于属性是底层的方法,我尝试了类似的方法:
private setProperty<T>(ref Action<T> property, T value) {
//meaningful code
}
Run Code Online (Sandbox Code Playgroud)
但无论如何我都会收到编译错误。
有没有一种直接的方法通过引用传递属性来以某种方式直接解决这个问题?
我有这个类,在那里我覆盖了 Object Equals:
public class Foo
{
public string string1 { get; set; }
public string string2 { get; set; }
public string string3 { get; set; }
public override bool Equals(object other)
{
if (!(other is Foo)) return false;
Foo otherFoo = (other as Foo);
return otherFoo.string1 == string1 && otherFoo.string2 == string2 && otherFoo.string3 == string3;
}
}
Run Code Online (Sandbox Code Playgroud)
我收到一个警告“覆盖 object.equals 但不覆盖 object.gethashcode”,我理解覆盖 GetHashCode 的必要性,以便我的类型根据可散列类型进行操作。
据我研究,为了使此代码唯一,通常使用 XOR 运算符,或者涉及素数乘法。所以,根据我的消息来源,来源1和源2我正在考虑我的GesHashCode覆盖方法这两个选项。
1:
public override int GetHashCode() {
return …
Run Code Online (Sandbox Code Playgroud) 我将我的打字稿项目移到了 win 7 计算机上。当 tsconfig 在我的 win 10 计算机上运行良好时,我收到此错误。我按照此处的建议删除了最后两个尾随逗号,但错误仍然存在。
我的 tsconfig:
{
"compileOnSave": true,
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"strict": true, /* Enable …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Office 脚本中重建一些 VBA 代码,因为我想通过 Microsoft Power Automate(以前的 Flow)自动执行。现在,我的处理数据透视表的代码部分遇到了问题。在 VBA 代码中,我使用:
Dim oWSHilfsPivot As Worksheet
Set oWSHilfsPivot = ActiveWorkbook.Sheets("Hilfs_Pivots")
With oWSHilfsPivot.PivotTables("PivotTable1").PivotFields("Projekt")
.PivotItems("(blank)").Visible = True
End With
Run Code Online (Sandbox Code Playgroud)
如何在 Office 脚本中重建过滤?当我尝试使用集成的 Office 脚本记录器记录它时,我得到:
function main(workbook: ExcelScript.Workbook) {
// Unknown event received with eventId:153
}
Run Code Online (Sandbox Code Playgroud)
因此,默认情况下,Office 脚本似乎还不支持此功能。当然,变量的定义有效,过滤是问题所在。;)
我很感激任何帮助。
我需要循环遍历枚举类型来填充反应组件中的一些选项。在下面找到枚举以及从中返回键和值的函数。
export enum ProyectType {
time,
hits,
value,
results
}
function projectTypeValues() {
const values = Object.keys(ProyectType).filter(k => typeof ProyectType[k as any] === "number"); // ["time", "hits", "value", "results"]
const keys = values.map(k => ProyectType[k as any]); // [0, 1, 2, 3]
}
Run Code Online (Sandbox Code Playgroud)
我不喜欢any
其中的类型,ProyectType[k as any]
所以我尝试了:
type EnumIndex = number | string;
ProyectType[k as EnumIndex]
Run Code Online (Sandbox Code Playgroud)
但我得到:Element implicitly has an 'any' type because index expression is not of type 'number'.ts(7015)
我认为索引器可以是数字或字符串类型,因为它Object.Keys
是一个包含 8 个元素的数组:["0","1","2","3","time","hits","value","results"] …
c# ×4
typescript ×4
properties ×2
vba ×2
copy ×1
equality ×1
excel ×1
gethashcode ×1
heap-memory ×1
javascript ×1
microsoft365 ×1
node.js ×1
office365 ×1
parsing ×1
pivot-table ×1
renderer ×1
setter ×1
source-maps ×1
stack-memory ×1
tsconfig ×1
webpack ×1