dudykr / stc Goto Github PK
View Code? Open in Web Editor NEWSpeedy TypeScript type checker
Home Page: https://stc.dudy.dev
License: Apache License 2.0
Speedy TypeScript type checker
Home Page: https://stc.dudy.dev
License: Apache License 2.0
The type of o6<number>()?.["x"];
above should be number | undefined
, but currently it's number
.
Relevant code for optional chaining is
The lines above should not report an error, but stc currently emits
The cause is
stc/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs
Lines 936 to 946 in 2ab93ad
and it should be fixed to allow assignment to nested modules
All types should have the same struct.
This is required to preserve current semantics.
And it should have fields for each type.
pub struct Metadata {
pub type_lit: TypeLitMetadata,
}
derive(Is)
of Type should be replaced with a smarter implementation, which is aware of normalization.Type#normalize
should be renamedI tried it, but for some unknown reasons there were regressions in performance and passing test list.
The branch is at https://github.com/kdy1/stc/tree/swc-update, and I'm planning to retry it in the future
Currently, type parameters are incorrectly stored, but when I tried storing them recursively, it resulted in a stack overflow.
I tried preventing stack overflow, but the 'validity' of type can't be ignored. Especially, Fixer
cannot give up fixing types, because it makes validity assertion of a type fail.
Allowing the constraints of type parameters to be invalid and fixing them each time contraint is used can be a solution, but it does not seem like a good solution.
Type::Ref
for constraints.This would make code dirty, but it would be easy to handle infinite recursion because many methods have their own logic to prevent infinite recursions. (fix()
does not have way to prevent recursion, and it's the problem)
assign
: (span: Span, l: &Type, r: &Type, opts: AssignOpts)
It will allow preprocessing builtin types
Module graph should return RModule
along with Arc<SourceMap>
, Arc<SourceFile>
.
It will allow using types from cache without degrading span.
Size regressed from 8MB to 12MB due to dudykr/stc-archive#31.
This is because of Visit
being shared between types and ast nodes.
This can be fixed by macros like noop_{visit, visit_mut, fold}_{ast, type}
.
As this is not critical for development, I merged the pr
In the files above, the assignment should succeed because Tag1
and Tag2
are enum
without an initializer, and enums without initializers are numbers while reducing.
This can be done by checking for enums in
stc/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs
Lines 666 to 693 in 2c2c822
This should not error, but currently, stc emits TupleIndexError
We should recover from the error based on the variant at
stc/crates/stc_ts_file_analyzer/src/analyzer/scope/vars.rs
Lines 250 to 263 in e59631e
This line should fail with TS2708
, but it fails with TS2539
.
The problematic code is at
stc/crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs
Lines 401 to 417 in e59631e
and we should use Errorr::convert_err
to adjust the error variant.
This line should not error, but stc fails to validate it because stc thinks the type of a1
is string[]
instead of [string, boolean]
.
I think the problematic code is
stc/crates/stc_ts_file_analyzer/src/analyzer/scope/vars.rs
Lines 292 to 326 in 2ab93ad
get_rest_elements
is returning a wrong type for the input above.This causes problems for check.sh
.
We should make it deterministic.
We need a debug impl which is replaced with dummy impl on release build.
The line above should not error because LHS is a rest pattern.
But currently stc fails with an error, because of the code below
stc/crates/stc_ts_file_analyzer/src/analyzer/scope/vars.rs
Lines 250 to 263 in e59631e
This is quite similar to #182, though.
We currently store types as vector, but we should store types as intersection.
Currently, we need to instantiate the full interface to infer the type of parameter.
This is too inefficient, and it can be done by
Attach id to type parameters and store type parameter information in the Scope
.
Store type arguments in types like Interface
, Class
, ..etc
The first option seems better.
Generated .d.ts file differs if strict mode is enabled.
We should remove ClassInstance
and add ClassDef
type.
ClassDef
is used for accessing static properties and Class
is used for accessing non-static properties.
Just wondering how to use stc
, at its current state.
Do I need to consume it as a library or run it through a test shim?
I cloned the repository, updated the dependencies through yarn
and compiled the project with rustc build
.
Alas, the resulting stc
binary only contains two subcommands (help and iterate) and simply providing a TypeScript source file simply returns a Found argument '<pathToTSFile>' which wasn't expected, or isn't valid in this context
The code above should fail with TS2348
, but currently it failes with TS2349
It has the context of tried to calculate return type
, which is used at
stc/crates/stc_ts_file_analyzer/src/analyzer/expr/call_new.rs
Lines 1973 to 1977 in e59631e
But error is NoCallablePropertyWithName
, which is TS2349
, and
So we should modify
stc/crates/stc_ts_file_analyzer/src/analyzer/expr/call_new.rs
Lines 821 to 825 in e59631e
to use different error variant.
This line should not report an argumentnt error because fields are optional.
The type of arguments are correctly inferred as [any, any, any, any]
but we should allow assignment of [1]
to [any, any, any, any]
.
stc/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs
Lines 1999 to 2010 in e59631e
The assignment logic for tuple should be aware of any
or undefined
and allow the length to mismatch for these cases.
After updating testing_macros
upto ^0.2.0, this error will be resolved.
Currently we are using v0.1.2 instead which seems to be failed to compile.
Compiling testing_macros v0.1.2
error[E0432]: unresolved import `proc_macro2::SourceFile`
--> /Users/flow/.cargo/registry/src/github.com-1ecc6299db9ec823/testing_macros-0.1.2/src/fixture.rs:6:19
|
6 | use proc_macro2::{SourceFile, Span};
| ^^^^^^^^^^ no `SourceFile` in the root
error[E0599]: no method named `source_file` found for struct `proc_macro2::Span` in the current scope
--> /Users/flow/.cargo/registry/src/github.com-1ecc6299db9ec823/testing_macros-0.1.2/src/lib.rs:58:34
|
58 | let file = Span::call_site().source_file();
| ^^^^^^^^^^^ method not found in `proc_macro2::Span`
Some errors have detailed explanations: E0432, E0599.
For more information about an error, try `rustc --explain E0432`.
error: could not compile `testing_macros` due to 2 previous errors
We are validating assign expressions twice, and this is super annoying
I postponed it from #170 because I have another item to work on
Basically,
//@strict: true
type ArgsUnion = [number, string] | [number, Error];
type TupleUnionFunc = (...params: ArgsUnion) => number;
const funcUnionTupleRest: TupleUnionFunc = (...params) => {
const [num, strOrErr] = params;
return num;
};
export { }
should work.
It can be done by fixing code at
stc/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs
Lines 2000 to 2011 in 9efde34
Compile time is delaying development.
ExpandRef
Assign
InferType
traits
.Handles assignments
Handles type inference.
Autocompletion in
Class name
Super class
Types
It can be inferred from usages. (including methods, as stc is fast)
Generate function when a function is not defined.
Generate method when a method is not defined.
import boss
: Block @material-ui/core
from being imported.
auto-recompile for kind of shared
modules (path dependencies).
Run directly from editor.
-[ ] Run tests from editor.
Actual type information in generic on hover.
Type inference issue
stc_ts_file_analyzer:
find_imported_var
: Support namespace imports.stc_ts_type_checker:
declare module 'http'
or declare namespace NodeJs
.Span is too implicit and it causes some bugs.
All metadata will be implemented as a field metadata
and all metadata structs must always return true for TypeEq
and EqIgnoreSpan
.
Type::Keyword
:
Type::TypeLit
:
is_exact
: Used for assignemnts. If is_exact
is false, unhandled rhs will be ignored.There's some logic to assign parameters in a reverse direction, but I'm not sure when it's applied.
stc/crates/stc_ts_file_analyzer/src/analyzer/assign/function.rs
Lines 743 to 765 in d62bfa2
I think the current logic is wrong, but not sure as I don't know enough about variance.
To be exact, I understood variance itself, but I'm not sure which variance I should use for an assignment in form of LHS = RHS as there are two types, and therefore two variances.
CowArcVec would be useful
BoxedCowArc is boxed variant
type TypePtr = BoxedCowArc
infer_type
: Fast path for Type::Mapped
with Type::Array
.normalize
: Partial expansion.fix
: Make it shallow.fix
: Reduce call.normalize
: Cache(?).I'll do this after #13.
I made a mistake while working on #15. I forgot splitting env.
derivedClassTransitivity.ts
:
// subclassing is not transitive when you can remove required parameters and add optional parameters
class C {
foo(x: number) { }
}
class D extends C {
foo() { } // ok to drop parameters
}
class E extends D {
foo(x?: string) { } // ok to add optional parameters
}
var c: C;
var d: D;
var e: E;
c = e;
var r = c.foo(1);
var r2 = e.foo('');
We need logic to compare private properties.
We should store the id of declaring class in properties, because properties from multiple class can be mixed.
I think AGPL 3.0 will not work for many vendors, but I don't want to change the license at now.
(Actually, I rebased the whole repo to add the AGPL License file to the first commit)
pub struct AType {
arc: Either<Type, Arc<Type>>,
}
AType.normalize()
returns type and Arc<Type>
is used while cloning.
This should success.
access_property
of ((BarProps#1 & object) | {})
is expected to fail, because {}
does not have the property.
But the type of fooProps
should be (BarProps#1 & object)
(without union)
I think the logic at
stc/crates/stc_ts_file_analyzer/src/analyzer/scope/vars.rs
Lines 483 to 500 in d121f20
Currently there's no clear way to distinguish typeof a === 'string' || typeof a === ' number'
and typeof a === 'string' && typeof a === ' number'
This should fail because a generator function uses the item from Iterable
as yield type.
i.e., g3
is inferred to emit a string as an item, and the inferred generator (Generator<number, any, undefined>
) is assigned to BadGenerator
.
It should file with
tests/tsc/types/builtin/generator/bad/1.ts:2:24 - error TS2322: Type 'Generator<string, any, undefined>' is not assignable to type 'BadGenerator'.
The types returned by 'next(...)' are incompatible between these types.
Type 'IteratorResult<string, any>' is not assignable to type 'IteratorResult<number, any>'.
Type 'IteratorYieldResult<string>' is not assignable to type 'IteratorResult<number, any>'.
Type 'IteratorYieldResult<string>' is not assignable to type 'IteratorYieldResult<number>'.
Type 'string' is not assignable to type 'number'.
But currently, stc fails to emit an error because stc uses the Iterator
interface instead of the Iterable
interface while inferring the yield
type.
stc/crates/stc_ts_file_analyzer/src/analyzer/stmt/return_type.rs
Lines 176 to 181 in e69d14c
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.