microsoft / microsoft/TypeScript
Assertion signature on contextual 'this'-parameter doesn't narrow and has no error
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
TypeScript Version: 4.2.0-dev.20210101
Search Terms: asserts this
Expected behavior:
Consistent behavior. Either
this.assert(v)narrowsvthis.asserthas an error about missing type annotation, no narrowing,this.returnNever()should not mark the following code as unreachable
Actual behavior:
No narrowing from asserts, no error on call expression, never-returning function has control flow effect.
Code
declare function makeContextualThisParameter<T>(cb: (this: T) => any): void;
makeContextualThisParameter<{assert(v: any): asserts v}>(function() {
const v = Boolean();
this.assert(v); // expected error here
v; // or narrowing `v: true` here
});
makeContextualThisParameter<{returnNever(): never}>(function() {
this.returnNever();
debugger; // this is marked as unreachable
});
Compiler Options
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"alwaysStrict": true,
"esModuleInterop": true,
"declaration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": 2,
"target": "ES2017",
"jsx": "React",
"module": "ESNext"
}
}
Playground Link: Provided
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci gli esempi di this contestuale nell’issue con TypeScript 4.2.0-dev.20210101 e le opzioni del compilatore indicate, usando il link fornito a Playground come punto di partenza. Traccia il modo in cui le firme di asserzione e le chiamate che restituiscono never influenzano il narrowing e la raggiungibilità, quindi aggiungi una copertura di regressione che mostri il comportamento previsto della diagnostica o del narrowing.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 25/100