feat(dts): type ngAcceptInputType_* with the transform's parameter type - #496
Open
ashley-hunter wants to merge 1 commit into
Open
ashley-hunter wants to merge 1 commit into
ashley-hunter wants to merge 1 commit into
Conversation
…type Library `.d.ts` declarations wrote `static ngAcceptInputType_<input>: unknown` for every input with a transform, so consumers' template type-checking accepted any value. ngtsc writes the type of the transform's first parameter, so e.g. `[count]="true"` against a `(value: string | number) => number` transform is a type error. That type is now printed the way ngtsc prints it: `@angular/core` names become `i0.Name`, string literals are re-quoted, spacing is normalised, local and global names are kept, `unknown` for a transform with no parameters. Two deliberate differences from ngtsc, both falling back to the previous `unknown`: - a type referencing another module: ngtsc adds `import * as iN` for it, but aliases numbered per source file can't be merged safely into bundled declaration files - an imported transform, whose signature can't be read from one file A member `@Input` overriding an `inputs:` entry decides the type, like the compiled inputs map. Also emits `"ng-component"` as the `.d.ts` selector of a component without one, as ngtsc does (it was `never`).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack (4/4): #493 inputs/outputs → #494 transform validation → #495
queries:→ #496.d.tstransform types. This is #496.Types
static ngAcceptInputType_<input>in library.d.tsoutput with the transform's parameter type, as ngtsc does.The bug
Every input with a transform was declared as
so a consumer's template type-checking accepted any value for it. ngtsc writes the type of the transform's first parameter, so
[count]="true"against(value: string | number) => numberis a type error.The fix
The type is printed the way ngtsc prints it (
directive/dts_type.rs):@angular/corenames becomei0.NameunknownA member
@Inputoverriding aninputs:entry decides the type, like the compiled inputs map.Two deliberate differences from ngtsc, both falling back to the previous
unknown:import * as iNfor it. These aliases are numbered per source file, which can't be merged safely into bundled declaration files, since the Vite.d.tsinjector combines every module's declarations.This PR also emits
"ng-component"as the.d.tsselector of a component without one, as ngtsc does (it wasnever).Tests
input transformsspecs fromngtsc_specand a probe covering most type forms are added to the ngtsc snapshot. The test maps ngtsc's other-module types tounknown(the documented difference), and the cases that need declarations from another file are skipped with that reason..d.ts, injected by the Vite plugin's helper, type-checks withskipLibCheck: false. ngtsc withstrictTemplatesaccepts a consumer with valid bindings against it, and rejects wrong ones (booleanfor astring | numbertransform, a value outside a literal union, a missing required input).