我正在使用HTML5 FileWriter API来保存我的webapp状态.我有一些JS定期调用FileWriter.write它(因此,随着时间的推移,该write方法被调用几次).默认情况下,FileWriter API使用'append'方法来编写不符合我需要的文件,因为我不想覆盖文件内容.
我第一次尝试这个:
this._writer.seek(0);
this._writer.write(content);
Run Code Online (Sandbox Code Playgroud)
当您编写的文本短于文件内容时,这不起作用.然后我尝试了这个:
this._writer.truncate(0);
this._writer.write(content);
Run Code Online (Sandbox Code Playgroud)
这段代码应该清除文件,然后编写我的新内容,但是在write调用方法时出现以下错误:
Uncaught InvalidStateError: An operation that depends on state cached in an interface object was made but the state had changed since it was read from disk.
Run Code Online (Sandbox Code Playgroud)
奇怪的是:当我调试代码(带断点)时,不会发生错误,好像FileWriter.truncate是一个异步方法......
我被困在这里,有什么想法吗?
我使用的是Chrome 30.0.1599.69
我正在使用SpringBoot设计REST API.与此同时,我正在构建一个使用该API的SPA.
为了安全起见,我选择了Basic Auth,它很容易设置.我现在面临401挑战问题.当我的SPA向我的API发出请求时,如果auth失败,浏览器会显示我想要删除的经典登录弹出窗口.
我在这里和那里阅读,当401响应包含值为'Basic'的WWW-authenticate标头时,浏览器显示此弹出窗口.
所以要删除它,根据Spring Security,我将提供我自己的AuthenticationEntryPoint.有点像Spring Boot默认完成的.我试过这个,但它不起作用,我在运行时得到一个堆栈.有任何想法吗?
这是我的代码
@Order(SecurityProperties.BASIC_AUTH_ORDER)
@Configuration
public class CustomWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
AuthenticationEntryPoint entryPoint = new CustomAuthenticationEntryPoint();
http
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.authorizeRequests()
.regexMatchers("/api/.*").authenticated().and()
.httpBasic().authenticationEntryPoint(entryPoint).and()
.exceptionHandling().authenticationEntryPoint(entryPoint).and()
.csrf().disable();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我在运行时获得的堆栈 mvn spring-boot:run
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:467)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation …Run Code Online (Sandbox Code Playgroud) 鉴于以下情况:
interface Foo {
attr: string;
(a: string): number;
(a: number): number;
}
Run Code Online (Sandbox Code Playgroud)
如何创建一种仅选择函数重载的类型,这意味着:
interface Bar {
(a: string): number;
(a: number): number;
}
Run Code Online (Sandbox Code Playgroud)
当只有一个呼叫签名时,我找到了解决方案,我的情况是当有多个呼叫签名时。
谢谢
我想为 Select 组件声明一个接口,该接口可以是多个或单个项目选择。
interface MySelect<T extends boolean> {
multi: T, // Is this a multiple items select
onChange: (item: T extends true ? string[]: string) => void // the onChange signature differs according to T
}
Run Code Online (Sandbox Code Playgroud)
它有效,但我必须显式设置泛型类型 T:
const mySelect: MySelect<true> = { // Here
multi: true, // And here
onChange: (items) => {}
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否有可能让 TS 从“multi”值中自动推断出 T:
const mySelect: MySelect = {
multi: true, // multi is true so T is true
onChange: (items) => {}
}
Run Code Online (Sandbox Code Playgroud)
重要更新:我希望“多个”是可选的(如果缺少或未定义键,它将默认为 …